HW Review

Sorting lists -- what we already know


In [5]:
x = ["duck", "aardvark", "crocodile", "emu", "bee",]

In [6]:
sorted(x)


Out[6]:
['aardvark', 'bee', 'crocodile', 'duck', 'emu']

In [7]:
# Sorts the original list
x.sort()

In [8]:
x


Out[8]:
['aardvark', 'bee', 'crocodile', 'duck', 'emu']

In [9]:
# Similar to order by DESC in SQL
sorted(x, reverse=True)


Out[9]:
['emu', 'duck', 'crocodile', 'bee', 'aardvark']

Sorting lists using functions in the key parameter


In [10]:
# Sorted by second letter of each string: aardvard, bee, emu, crocodile, duck
# We're going to do something like this:
# sorted(x, key=???)

In [11]:
def get_second_letter(s):
    return s[1]

In [12]:
get_second_letter("cheese")


Out[12]:
'h'

In [13]:
# You are passing our get_second_letter function as a parameter to your sorted() function
sorted(x, key=get_second_letter)


Out[13]:
['aardvark', 'bee', 'emu', 'crocodile', 'duck']

In [14]:
type(12)


Out[14]:
int

In [15]:
type("hello")


Out[15]:
str

In [16]:
# Function is just another kind of value in Python -- therefore, you can pass them around like variables
type(get_second_letter)


Out[16]:
function

Lambda functions

A alternate way of writing functions; written on a single line.


In [17]:
# Normal function:
def get_second_letter(s):
    return s[1]

# The above function is pretty simple -- passing only one parameter, and get a simple return statement
get_second_letter = lambda s: s[1] # This translates EXACTLY to the function above; achieves exactly the same thing

# Note that if we had expressions other than our return statement, we could NOT use a lambda function

In [18]:
get_second_letter("hello")


Out[18]:
'e'

In [19]:
# This expression itself is a function
# This function does not need to have a variable associated with it; it doesn't need a name! 
# Allows you to define a function without assigning it to a variable
# Great when you only want to use a function once 

type(lambda s: s[1])


Out[19]:
function

In [20]:
sorted(x, key=lambda s: s[1])

# same as: sorted(x, key=get_second_letter)


Out[20]:
['aardvark', 'bee', 'emu', 'crocodile', 'duck']

The extra credit from HW4


In [21]:
planets = [
 {'diameter': 0.382,
  'mass': 0.06,
  'moons': 0,
  'name': 'Mercury',
  'orbital_period': 0.24,
  'rings': 'no',
  'type': 'terrestrial'},
 {'diameter': 0.949,
  'mass': 0.82,
  'moons': 0,
  'name': 'Venus',
  'orbital_period': 0.62,
  'rings': 'no',
  'type': 'terrestrial'},
 {'diameter': 1.00,
  'mass': 1.00,
  'moons': 1,
  'name': 'Earth',
  'orbital_period': 1.00,
  'rings': 'no',
  'type': 'terrestrial'},
 {'diameter': 0.532,
  'mass': 0.11,
  'moons': 2,
  'name': 'Mars',
  'orbital_period': 1.88,
  'rings': 'no',
  'type': 'terrestrial'},
 {'diameter': 11.209,
  'mass': 317.8,
  'moons': 67,
  'name': 'Jupiter',
  'orbital_period': 11.86,
  'rings': 'yes',
  'type': 'gas giant'},
 {'diameter': 9.449,
  'mass': 95.2,
  'moons': 62,
  'name': 'Saturn',
  'orbital_period': 29.46,
  'rings': 'yes',
  'type': 'gas giant'},
 {'diameter': 4.007,
  'mass': 14.6,
  'moons': 27,
  'name': 'Uranus',
  'orbital_period': 84.01,
  'rings': 'yes',
  'type': 'ice giant'},
 {'diameter': 3.883,
  'mass': 17.2,
  'moons': 14,
  'name': 'Neptune',
  'orbital_period': 164.8,
  'rings': 'yes',
  'type': 'ice giant'}]

In [22]:
[p['name'] for p in sorted(planets, key=lambda x: x['moons'])]


Out[22]:
['Mercury', 'Venus', 'Earth', 'Mars', 'Neptune', 'Uranus', 'Saturn', 'Jupiter']

In [23]:
def get_moon_count(d):
    return d['moons']

[p['name'] for p in sorted(planets, key=get_moon_count)]


Out[23]:
['Mercury', 'Venus', 'Earth', 'Mars', 'Neptune', 'Uranus', 'Saturn', 'Jupiter']

What it would look like in SQL:

SELECT name FROM planets
ORDER BY moons

In [24]:
[p['name'] for p in sorted(planets, key=lambda d: d['diameter'], reverse=True)]


Out[24]:
['Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Earth', 'Venus', 'Mars', 'Mercury']

Aside: putting \ in a python line allows you to write the rest of what you were writing on the next line!


In [25]:
[p['name'] for p in \
sorted(planets, key=lambda d: d['diameter'], reverse=True) \
if p['diameter'] > 4]


Out[25]:
['Jupiter', 'Saturn', 'Uranus']

Tuples (tuple is pronounced like it rhymes with 'supple')

Tuple is kind of like a strict list. It looks kind of like a list.


In [26]:
t = (5, 10, 15)

In [27]:
type(t)


Out[27]:
tuple

In [28]:
t[0]


Out[28]:
5

In [29]:
for item in t:
    print(item * item)


25
100
225

The main difference between a tuple and a list: you can't add new values to a tuple.


In [30]:
t.append(30)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-30-e0d05117f4e7> in <module>()
----> 1 t.append(30)

AttributeError: 'tuple' object has no attribute 'append'

In [31]:
carefree_list = [5, 10, 15, 20, 25]

In [32]:
carefree_list


Out[32]:
[5, 10, 15, 20, 25]

In [33]:
carefree_list.append(30)

In [34]:
carefree_list


Out[34]:
[5, 10, 15, 20, 25, 30]

In [35]:
carefree_list[1] = "Mr. Fluffypants"

In [36]:
carefree_list


Out[36]:
[5, 'Mr. Fluffypants', 15, 20, 25, 30]

A tuple is called an immutable data type. You can't change it after it has been defined!

Benefits of using tuples:

  • If you are passing data to a function, you know that it will not change your data. Fewer bugs in your data!
  • It's also memory efficient. With lists, Python has to allocate more memory than it (probably) needs; expanding the memory allocated to a data structure is computationally expensive. With immutable data structures, Python knows how big it is and how big it always will be.

In [37]:
# Immutable data type
# You can't change it after it has been defined 
t[1] = "Mr. Fluffypants"


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-39ca4188a8d7> in <module>()
      1 # Immutable data type
      2 # You can't change it after it has been defined
----> 3 t[1] = "Mr. Fluffypants"

TypeError: 'tuple' object does not support item assignment

In [38]:
hello = [1, 2, 3]

In [39]:
foo = (1, 2, 3)

In [40]:
import sys
sys.getsizeof(hello)


Out[40]:
88

In [41]:
# Our tuple take up less memory! 
sys.getsizeof(foo)


Out[41]:
72

In most applications, we want lists because we're working with data. We want to be able to append, delete or otherwise modify our data. A list is like a notebook and a tuple is stone tablet.

The standard library will have functions that return data structures as tuples (because it has an interest in efficiency).

Back to regular expressions!

Grouping with multiple matches in the same string


In [42]:
import re
test = "one 1 two 2 three 3 four 4 five 5"

# we want every occurence of a word followed by a number
# .findall() finds every occurence of the regular expression in our string 
re.findall(r"\w+ \d", test)


Out[42]:
['one 1', 'two 2', 'three 3', 'four 4', 'five 5']

In [43]:
# We want to access one and 1 individually
for item in re.findall(r"\w+ \d", test):
    print(number_s)
    print(number_i)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-43-bde8c3eadc68> in <module>()
      1 # We want to access one and 1 individually
      2 for item in re.findall(r"\w+ \d", test):
----> 3     print(number_s)
      4     print(number_i)

NameError: name 'number_s' is not defined

In [44]:
# This particular example is trivial because we know we can do this:
for item in re.findall(r"\w+ \d", test):
    x = item.split(" ")
    print(x[0])
    print(x[1])


one
1
two
2
three
3
four
4
five
5

In [45]:
test = "one 1 two 2 three 3 four 4 five 5"
re.findall(r"(\w+) (\d)", test)

# returns a list of tuples


Out[45]:
[('one', '1'), ('two', '2'), ('three', '3'), ('four', '4'), ('five', '5')]

In [46]:
all_subjects = open("enronsubjects.txt").read()

In [47]:
re.findall(r"\d{3}-\d{3}-\d{4}", all_subjects)


Out[47]:
['713-853-4743',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '281-296-0573',
 '713-851-2499',
 '713-345-7896',
 '713-345-7896',
 '713-345-7896',
 '713-345-7896',
 '713-345-7896',
 '281-367-8953',
 '713-528-0759',
 '713-850-9002',
 '713-703-8294',
 '614-888-9588',
 '713-767-8686',
 '303-571-6135',
 '281-537-9334',
 '800-937-6563',
 '800-937-6563',
 '888-296-1938']

In [48]:
# What if we wanted to grab them as separate items? 
re.findall(r"(\d{3})-(\d{3})-(\d{4})", all_subjects)


Out[48]:
[('713', '853', '4743'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('713', '222', '7667'),
 ('281', '296', '0573'),
 ('713', '851', '2499'),
 ('713', '345', '7896'),
 ('713', '345', '7896'),
 ('713', '345', '7896'),
 ('713', '345', '7896'),
 ('713', '345', '7896'),
 ('281', '367', '8953'),
 ('713', '528', '0759'),
 ('713', '850', '9002'),
 ('713', '703', '8294'),
 ('614', '888', '9588'),
 ('713', '767', '8686'),
 ('303', '571', '6135'),
 ('281', '537', '9334'),
 ('800', '937', '6563'),
 ('800', '937', '6563'),
 ('888', '296', '1938')]

In [49]:
for item in re.findall(r"(\d{3})-(\d{3})-(\d{4})", all_subjects):
    print(item[0])


713
713
713
713
713
713
713
713
713
713
713
281
713
713
713
713
713
713
281
713
713
713
614
713
303
281
800
800
888

In [50]:
[item[0] for item in re.findall(r"(\d{3})-(\d{3})-(\d{4})", all_subjects)]


Out[50]:
['713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '281',
 '713',
 '713',
 '713',
 '713',
 '713',
 '713',
 '281',
 '713',
 '713',
 '713',
 '614',
 '713',
 '303',
 '281',
 '800',
 '800',
 '888']

Finding monetary amounts in the subject lines

match something like $ 10 m, k, b


In [51]:
# dollar sign, followed by some number of digits, followed by 0 or 1 space(s), followed by some number of alphanumberic chracters
r"\$(\d+) ?(\w+)"


Out[51]:
'\\$(\\d+) ?(\\w+)'

In [52]:
re.findall(r"\$(\d+) ?(\w+)", all_subjects)


Out[52]:
[('22', '8'),
 ('22', '8'),
 ('10', 'M'),
 ('10', 'M'),
 ('10', 'M'),
 ('10', 'M'),
 ('6', '8'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('25', 'million'),
 ('82', '0'),
 ('82', '0'),
 ('40', 'Million'),
 ('27', 'Billion'),
 ('27', 'Billion'),
 ('5', '0'),
 ('5', '0'),
 ('89', '5'),
 ('89', '5'),
 ('1', '9'),
 ('1', '9'),
 ('1', '9'),
 ('1', '9'),
 ('870', 'K'),
 ('870', 'K'),
 ('14', '1'),
 ('14', '1'),
 ('21', 'billion'),
 ('6', 'million'),
 ('14', 'bln'),
 ('14', 'bln'),
 ('100', 'PRICE'),
 ('250', 'Cap'),
 ('350', 'MM'),
 ('1', '2'),
 ('1', '2'),
 ('1', '2'),
 ('1', '2'),
 ('10', 'Three'),
 ('70', '0'),
 ('70', '0'),
 ('70', '0'),
 ('10', 'you'),
 ('10', 'you'),
 ('13', 'B'),
 ('13', 'B'),
 ('100', 'on'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('500', 'k'),
 ('2', 'Billion'),
 ('2', 'Billion'),
 ('2', 'Billion'),
 ('2', 'Billion'),
 ('97', '1'),
 ('97', '1'),
 ('97', '1'),
 ('97', '1'),
 ('97', '1'),
 ('97', '1'),
 ('1', 'Billion'),
 ('1', 'Billion'),
 ('39', 'in'),
 ('39', 'in'),
 ('1', '0'),
 ('1', '0'),
 ('14', '9'),
 ('5', '0'),
 ('5', '0'),
 ('5', '0'),
 ('2', '1'),
 ('21', 'P'),
 ('550', 'Million'),
 ('455', 'Million'),
 ('5', 'million'),
 ('5', 'million'),
 ('5', 'million'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('100', 'Price'),
 ('2', '0'),
 ('2', '0'),
 ('2', '0'),
 ('2', '0'),
 ('10', '0'),
 ('10', '0'),
 ('10', '0'),
 ('2', '0'),
 ('2', '0'),
 ('2', '9'),
 ('2', '9'),
 ('2', '9'),
 ('2', '9'),
 ('2', '9'),
 ('2', '9'),
 ('160', '0'),
 ('160', '0'),
 ('160', '0'),
 ('160', '0'),
 ('160', '0'),
 ('160', '0'),
 ('160', '0'),
 ('2', 'Billion'),
 ('2', 'Billion'),
 ('2', 'Billion'),
 ('6', '7'),
 ('100', 'mil'),
 ('50', 'per'),
 ('21', '2'),
 ('21', '2'),
 ('21', '2'),
 ('21', '2'),
 ('21', '2'),
 ('21', '2'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('19', '5'),
 ('4', '2'),
 ('4', '2'),
 ('4', '2'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('7', 'MM'),
 ('1', '0'),
 ('1', '0'),
 ('1', '6'),
 ('1', '6'),
 ('1', '6'),
 ('8', 'Million'),
 ('8', 'Million'),
 ('500', 'mm'),
 ('500', 'mm'),
 ('500', 'mm'),
 ('80', 'million'),
 ('80', 'million'),
 ('80', 'million'),
 ('80', 'million'),
 ('80', 'million'),
 ('80', 'million'),
 ('80', 'million'),
 ('50', 'M'),
 ('102', 'Target'),
 ('102', 'Target'),
 ('20', '0'),
 ('5', '0'),
 ('25', 'Million'),
 ('25', 'Million'),
 ('25', 'Million'),
 ('120', 'EXTRA'),
 ('120', 'EXTRA'),
 ('45', 'Million'),
 ('45', 'Million'),
 ('14', '7'),
 ('14', '7'),
 ('14', '7'),
 ('14', '7'),
 ('14', '7'),
 ('14', '7'),
 ('14', '7'),
 ('600', 'B'),
 ('600', 'B'),
 ('14', '7'),
 ('14', '7'),
 ('14', '7'),
 ('24', '0'),
 ('24', '0'),
 ('2', '2'),
 ('2', '2'),
 ('2', '2'),
 ('100', 'k'),
 ('7', '7'),
 ('18', '3'),
 ('130', 'Million'),
 ('130', 'Million'),
 ('130', 'Million'),
 ('1', 'mm'),
 ('1', '0'),
 ('1', '0'),
 ('1', '0'),
 ('1', '0'),
 ('1', '0'),
 ('1', '0'),
 ('128', 'Return'),
 ('128', 'Return')]

In [53]:
# Let's refine our search
re.findall(r"\$(\d+) ?([bBmM])", all_subjects)


Out[53]:
[('10', 'M'),
 ('10', 'M'),
 ('10', 'M'),
 ('10', 'M'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('25', 'm'),
 ('40', 'M'),
 ('27', 'B'),
 ('27', 'B'),
 ('21', 'b'),
 ('6', 'm'),
 ('14', 'b'),
 ('14', 'b'),
 ('350', 'M'),
 ('13', 'B'),
 ('13', 'B'),
 ('2', 'B'),
 ('2', 'B'),
 ('2', 'B'),
 ('2', 'B'),
 ('1', 'B'),
 ('1', 'B'),
 ('550', 'M'),
 ('455', 'M'),
 ('5', 'm'),
 ('5', 'm'),
 ('5', 'm'),
 ('7', 'M'),
 ('7', 'M'),
 ('7', 'M'),
 ('7', 'M'),
 ('7', 'M'),
 ('7', 'M'),
 ('2', 'B'),
 ('2', 'B'),
 ('2', 'B'),
 ('100', 'm'),
 ('7', 'M'),
 ('7', 'M'),
 ('7', 'M'),
 ('8', 'M'),
 ('8', 'M'),
 ('500', 'm'),
 ('500', 'm'),
 ('500', 'm'),
 ('80', 'm'),
 ('80', 'm'),
 ('80', 'm'),
 ('80', 'm'),
 ('80', 'm'),
 ('80', 'm'),
 ('80', 'm'),
 ('50', 'M'),
 ('25', 'M'),
 ('25', 'M'),
 ('25', 'M'),
 ('45', 'M'),
 ('45', 'M'),
 ('600', 'B'),
 ('600', 'B'),
 ('130', 'M'),
 ('130', 'M'),
 ('130', 'M'),
 ('1', 'm')]

In [54]:
# Add up all the values mentioned in the subject lines 
vals = []
for item in re.findall(r"\$(\d+) ?([bBmM])", all_subjects):
    
    multiplier = item[1].lower()
    number_val = int(item[0])
    if multiplier == 'k':
        number_val *= 1000
    elif multiplier == 'm':
        number_val *= 1000000
    elif multiplier == 'b':
        number_val *= 1000000000
    vals.append(number_val)
    
sum(vals)


Out[54]:
1349651000000

The point: re.findall() returns a list of tuples because the number of groups that will be returned will not be changed.

Substitution with regular expressions


In [55]:
message = "This is a test, this is only a test"

In [56]:
# You can chain .replace()
message.replace("this", "that").replace("test", "walrus")


Out[56]:
'This is a walrus, that is only a walrus'

In [57]:
re.findall(r"\d{3}-\d{3}-\d{4}", all_subjects)


Out[57]:
['713-853-4743',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '713-222-7667',
 '281-296-0573',
 '713-851-2499',
 '713-345-7896',
 '713-345-7896',
 '713-345-7896',
 '713-345-7896',
 '713-345-7896',
 '281-367-8953',
 '713-528-0759',
 '713-850-9002',
 '713-703-8294',
 '614-888-9588',
 '713-767-8686',
 '303-571-6135',
 '281-537-9334',
 '800-937-6563',
 '800-937-6563',
 '888-296-1938']

In [58]:
message = "This is a test, this is only a test"

In [59]:
# re.sub(???, ???, ???): takes 3 parameters
# word to find, the word to replace found word with, a string
re.sub(r"[Tt]his", "that", message)


Out[59]:
'that is a test, that is only a test'

In [60]:
message


Out[60]:
'This is a test, this is only a test'

In [61]:
re.sub(r"\b\w+\b", "walrus", message)


Out[61]:
'walrus walrus walrus walrus, walrus walrus walrus walrus walrus'

In [62]:
# You could also pass a function as the second parameter
# re.sub(r"\b\w+\b", function, message)

In [63]:
anon = re.sub(r"\d{3}-\d{3}-\d{4}", "555-555-5555", all_subjects)

In [64]:
re.findall(r"\d{3}-\d{3}-\d{4}", anon)


Out[64]:
['555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555',
 '555-555-5555']

In [65]:
# Find twenty characters before and after our phone numbers 
re.findall(r".{,20}\d{3}-\d{3}-\d{4}.{,20}", anon)


Out[65]:
['Call Chris 555-555-5555',
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 "git's Contact Info: 555-555-5555",
 'Terry 555-555-5555',
 'Re: 555-555-5555',
 "W: Mark's number is 555-555-5555",
 "E: Mark's number is 555-555-5555",
 "Mark's number is 555-555-5555",
 "E: Mark's number is 555-555-5555",
 "Mark's number is 555-555-5555",
 'ease call for map 1-555-555-5555 or',
 'Bill F 555-555-5555',
 ' Jonathon Fairbanks 555-555-5555w/555-555-5555c and ',
 'irk re CGAS lawsuit 555-555-5555',
 ' Johnston at Dynegy 555-555-5555 re Debbie Chance',
 'data /Tracy Ashmore-555-555-5555',
 'Re: Kaye Ellis - 555-555-5555 (home)',
 'n Paper Conf Call 1-555-555-5555,',
 'O policies.  Dial 1-555-555-5555 and ask for the Jul',
 'nf Call (Alvarez) 1-555-555-5555, HC:']

In [66]:
anon2 = re.sub(r"(\d{3})-(\d{3})-(\d{4})", r"\1-\2-XXXX", anon)

In [67]:
re.findall(r".{,20}\d{3}-\d{3}-X{4}.{,20}", anon2)


Out[67]:
['Call Chris 555-555-XXXX',
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 "git's Contact Info: 555-555-XXXX",
 'Terry 555-555-XXXX',
 'Re: 555-555-XXXX',
 "W: Mark's number is 555-555-XXXX",
 "E: Mark's number is 555-555-XXXX",
 "Mark's number is 555-555-XXXX",
 "E: Mark's number is 555-555-XXXX",
 "Mark's number is 555-555-XXXX",
 'ease call for map 1-555-555-XXXX or',
 'Bill F 555-555-XXXX',
 ' Jonathon Fairbanks 555-555-XXXXw/555-555-XXXXc and ',
 'irk re CGAS lawsuit 555-555-XXXX',
 ' Johnston at Dynegy 555-555-XXXX re Debbie Chance',
 'data /Tracy Ashmore-555-555-XXXX',
 'Re: Kaye Ellis - 555-555-XXXX (home)',
 'n Paper Conf Call 1-555-555-XXXX,',
 'O policies.  Dial 1-555-555-XXXX and ask for the Jul',
 'nf Call (Alvarez) 1-555-555-XXXX, HC:']

HTML to SQL

We've done a lot of work getting data out of databases, but SQL databases are also a good place to store your data.

Scraping menupages


In [68]:
from urllib.request import urlretrieve
urlretrieve("https://raw.githubusercontent.com/ledeprogram/data-and-databases/master/menupages-morningside-heights.html",
           "menupages-morningside-heights.html")


Out[68]:
('menupages-morningside-heights.html',
 <http.client.HTTPMessage at 0x104a82d68>)

We want to store:

  • restuarant name
  • price
  • cuisine

Research phase:

  • every restaurant has a <tr> that is a child of the <table> tag with class search-results
  • restaurants seem to be in <td> tags with class name-address
  • restuarant names are in an <a> tag inside that <td>
  • restaurant price in a <span> inside a <td> with class price
  • the cuisine of the restaurant is in a <td> tag that has no class. 5th <td> tag that is a child of the restaurant's <tr> tag

Target:

  • a list of dictionary (this will be our intermediary format before we make an actual SQL table)

      [
          { "name": "Brad's", "price": "1", "cuisine": '['coffee'] },
          { "name": "Cafe Nana", "price": "0", "cuisine": '['Middle Eastern', 'Kosher'] },
          ...
      ]

In [69]:
from bs4 import BeautifulSoup

In [70]:
raw_html = open("menupages-morningside-heights.html").read() # read in as a string
soup = BeautifulSoup(raw_html, "html.parser") # parse it as html

In [71]:
search_table = soup.find("table", {"class": "search-results"})
table_body = search_table.find("tbody")

for tr_tag in table_body.find_all('tr'):
    print(tr_tag) # Print to make sure your code is working as you hope! 
    print("______________________\n") # I like using separators to make prints easier to process!


<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "7116"' href="/restaurants/milano-market/">Milano Market</a> Deli Food, Sandwiches<br/> 2892 Broadway | Btwn 112th &amp; 113th St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>deli, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "17586"' href="/restaurants/massawa/">Massawa</a> Ethiopian, African<br/> 1239 Amsterdam Ave | At 121st St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "17586"' href="https://www.seamless.com/r/a/1124/menu/menupages/24697?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>ethiopian, african</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "18020"' href="/restaurants/china-place/">China Place</a> Chinese, Japanese, Sushi<br/> 3141 Broadway | Btwn Tiemann Pl &amp; La Salle St  </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>chinese, japanese, sushi</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "18297"' href="/restaurants/subsconscious/">Subsconscious</a> Cheesesteaks, Deli Food, Sandwiches, Salads<br/> 1213 Amsterdam Ave | Btwn 119th &amp; 120th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "18297"' href="https://www.seamless.com/r/a/1124/menu/menupages/260684?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>cheese-steaks, deli, sandwiches, salads</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "18662"' href="/restaurants/famous-famiglia-5/">Famous Famiglia</a> Italian, Pizza<br/> 2859 Broadway | At 111th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "18662"' href="https://www.seamless.com/r/a/1124/menu/menupages/66387?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>italian, pizza</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "18823"' href="/restaurants/kitchenette/">Kitchenette</a> Bakery &amp; Pastries, American, Desserts<br/> 1272 Amsterdam Ave | At 122nd St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "18823"' href="https://www.seamless.com/r/a/1124/menu/menupages/267149?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>bakery-pastries, american, desserts</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "18854"' href="/restaurants/v-t-pizza/">V &amp; T Pizza</a> Italian, Pizza<br/> 1024 Amsterdam Ave | Btwn 110th &amp; 111th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "18854"' href="https://www.seamless.com/r/a/1124/menu/menupages/263773?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>italian, pizza</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "47426"' href="/restaurants/new-aroma/">New Aroma</a> Chinese<br/> 465 W 125th St | Btwn Morningside &amp; Amsterdam Ave  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>chinese</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48702"' href="/restaurants/peking-garden/">Peking Garden</a> Chinese<br/> 3163 Broadway | Btwn 124th &amp; 125th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>chinese</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48704"' href="/restaurants/toms-restaurant-2/">Tom's Restaurant</a> Diner<br/> 2880 Broadway | At 112th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>diner</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48706"' href="/restaurants/pisticci/">Pisticci</a> Italian<br/> 125 La Salle St | Btwn Broadway &amp; Claremont Ave  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>italian</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48710"' href="/restaurants/deluxe/">Deluxe</a> Diner, American<br/> 2896 Broadway | Btwn 112th &amp; 113th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48710"' href="https://www.seamless.com/r/a/1124/menu/menupages/2422?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>diner, american</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48713"' href="/restaurants/toast/">Toast</a> American, Bar Food<br/> 3157 Broadway | Btwn Tiemann Pl &amp; La Salle St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american, bar-food</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48714"' href="/restaurants/toms-delicious-pizza/">Tom's Delicious Pizza</a> Italian, Pizza<br/> 3161 Broadway | Btwn Lasalle &amp; Tiemann Pl   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48714"' href="https://www.seamless.com/r/a/1124/menu/menupages/66485?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>italian, pizza</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48764"' href="/restaurants/west-place/">West Place</a> Chinese<br/> 1288 Amsterdam Ave | Btwn 123rd &amp; LaSalle St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>chinese</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48765"' href="/restaurants/che-bella-pizza/">Che' Bella Pizza</a> Italian, Pizza<br/> 1215 Amsterdam Ave | Btwn 119th &amp; 120th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48765"' href="https://www.seamless.com/r/a/1124/menu/menupages/261047?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>italian, pizza</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48771"' href="/restaurants/ajanta/">Ajanta</a> Indian<br/> 1237 Amsterdam Ave | Btwn 120th &amp; 121st St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48771"' href="https://www.seamless.com/r/a/1124/menu/menupages/66330?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>indian</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48772"' href="/restaurants/panino-sportivo-roma/">Panino Sportivo Roma</a> Italian, Coffee &amp; Tea, Sandwiches<br/> 1231 Amsterdam Ave | Btwn 120th &amp; 121st St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>italian, coffee-tea, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48782"' href="/restaurants/max-soha/">Max Soha</a> Italian<br/> 1274 Amsterdam Ave | At 123rd St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>italian</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48810"' href="/restaurants/strokos-pizza/">Strokos Pizza</a> Deli Food, Pizza, Sandwiches, Chicken<br/> 1090 Amsterdam Ave | At 114th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48810"' href="https://www.seamless.com/r/a/1124/menu/menupages/284424?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price3">3</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>deli, pizza, sandwiches, chicken</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48811"' href="/restaurants/camilles/">Camille's</a> American<br/> 1135 Amsterdam Ave | At 116th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48811"' href="https://www.seamless.com/r/a/1124/menu/menupages/304834?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48816"' href="/restaurants/amsterdam-restaurant/">Amsterdam Restaurant</a> American (New), Tapas<br/> 1207 Amsterdam Ave | Btwn 119th &amp; 120th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american-new, tapas</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48856"' href="/restaurants/nussbaum-wu/">Nussbaum &amp; Wu</a> Deli Food, Sandwiches, Bagels, Salads<br/> 2897 Broadway | At 113th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48856"' href="https://www.seamless.com/r/a/1124/menu/menupages/264262?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>deli, sandwiches, bagels, salads</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48858"' href="/restaurants/amirs-falafel/">Amir's Grill</a> Middle Eastern<br/> 2911 Broadway | Btwn 113th &amp; 114th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48858"' href="https://www.seamless.com/r/a/1124/menu/menupages/274793?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>middle-eastern</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48859"' href="/restaurants/m2m-morning-to-midnight/">M2M - Morning To Midnight</a> Japanese, Sushi, Deli Food, Sandwiches<br/> 2935 Broadway | Btwn 114th &amp; 115th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>japanese, sushi, deli, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48869"' href="/restaurants/the-mill/">The Mill</a> Korean<br/> 2895 Broadway | At 113th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "48869"' href="https://www.seamless.com/r/a/1124/menu/menupages/291094?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>korean</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "48895"' href="/restaurants/le-monde/">Le Monde</a> French, Bistro<br/> 2885 Broadway | Btwn 112th &amp; 113th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>french, bistro</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "49084"' href="/restaurants/melbas/">Melba's</a> American (New), Soul Food<br/> 300 W 114th St | At Frederick Douglass Blvd   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "49084"' href="https://www.seamless.com/r/a/1124/menu/menupages/305207?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american-new, soul-food</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "64407"' href="/restaurants/chuck-e-cheeses-4/">Chuck E Cheese's</a> Pizza, American<br/> 280 St Nicholas Ave | At 124th St  </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>pizza, american</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "232674"' href="/restaurants/haagen-dazs-5/">Haagen-Dazs</a> Desserts<br/> 2905 Broadway | Btwn 113th &amp; 114th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "232674"' href="https://www.seamless.com/r/a/1124/menu/menupages/309443?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>desserts</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "249497"' href="/restaurants/orens-9/">Oren's</a> Coffee &amp; Tea, Sandwiches<br/> 2882 Broadway | Btwn 112th &amp; 113th St  </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "252863"' href="/restaurants/dinosaur-bar-b-que/">Dinosaur Bar-B-Que</a> Barbecue, Soul Food<br/> 700 W 125th St | At Riverside Dr   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "252863"' href="https://www.seamless.com/r/a/1124/menu/menupages/262149?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price3">3</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>barbecue, soul-food</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "259650"' href="/restaurants/symposium-greek-restaurant/">Symposium Greek Restaurant</a> Greek, Vegetarian<br/> 544 W 113th St | Btwn Broadway &amp; Amsterdam Ave   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "259650"' href="https://www.seamless.com/r/a/1124/menu/menupages/316959?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>greek, vegetarian</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "259651"' href="/restaurants/koronet-pizza/">Koronet Pizza</a> Pizza<br/> 2848 Broadway | Btwn 110th &amp; 111th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "259651"' href="https://www.seamless.com/r/a/1124/menu/menupages/304074?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>pizza</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "260320"' href="/restaurants/the-heights-bar-grill/">The Heights Bar &amp; Grill</a> Southwestern, Tapas, Bar Food<br/> 2867 Broadway | Btwn 111th &amp; 112th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>southwestern, tapas, bar-food</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "260321"' href="/restaurants/cafe-nana/">Cafe Nana</a> Middle Eastern, Kosher<br/> 606 W 115th St | Btwn Broadway &amp; Riverside Dr   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "260321"' href="https://www.seamless.com/r/a/1124/menu/menupages/305026?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>middle-eastern, kosher</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "271631"' href="/restaurants/hamilton-deli/">Hamilton Deli</a> Deli Food, Sandwiches<br/> 1129 Amsterdam Ave | Btwn 115th &amp; 116th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "271631"' href="https://www.seamless.com/r/a/1124/menu/menupages/263574?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>deli, sandwiches</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "272490"' href="/restaurants/community-food-juice/">Community Food &amp; Juice</a> American (New), Smoothies &amp; Juices, Vegetarian, Healthy, Local/Organic<br/> 2893 Broadway | Btwn 112th &amp; 113th St  </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>american-new, smoothies-juices, vegetarian, healthy, localorganic</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "280232"' href="/restaurants/haakons-hall/">Haakon's Hall</a> American, Scandinavian<br/> 1187 Amsterdam Ave | Btwn 118th &amp; 119th St  </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>american, scandinavian</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "285753"' href="/restaurants/el-porton/">El Porton</a> Mexican<br/> 3151 Broadway | Btwn La Salle St &amp; Tiemann Pl   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "285753"' href="https://www.seamless.com/r/a/1124/menu/menupages/259315?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td>mexican</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "295238"' href="/restaurants/brads/">Brad's</a> Coffee &amp; Tea<br/> 2920 Broadway | At 115th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "295238"' href="https://www.seamless.com/r/a/1124/menu/menupages/261868?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "295701"' href="/restaurants/mels-burger-bar/">Mel's Burger Bar</a> Burgers, Bar Food<br/> 2850 Broadway | Btwn 110th &amp; 111th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "295701"' href="https://www.seamless.com/r/a/1124/menu/menupages/320935?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>burgers, bar-food</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "296507"' href="/restaurants/bettolona/">Bettolona</a> Italian, Pizza, Local/Organic<br/> 3143 Broadway | Btwn La Salle St &amp; Tiemann Pl   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "296507"' href="https://www.seamless.com/r/a/1124/menu/menupages/81941?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>italian, pizza, localorganic</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "303538"' href="/restaurants/five-guys-9/">Five Guys</a> Burgers, Hot Dogs<br/> 2847 Broadway | Btwn 110th &amp; 111th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>burgers, hot-dogs</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "305919"' href="/restaurants/nikko/">Nikko</a> Chinese, Japanese, Sushi, Teahouses<br/> 1280 Amsterdam Ave | At 123rd St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "305919"' href="https://www.seamless.com/r/a/1124/menu/menupages/264367?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>chinese, japanese, sushi, teahouses</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "308682"' href="/restaurants/falafel-on-broadway/">Falafel on Broadway</a> Middle Eastern<br/> 3151 Broadway | Btwn Tiemann Pl &amp; Lasalle St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "308682"' href="https://www.seamless.com/r/a/1124/menu/menupages/274644?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>middle-eastern</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "333625"' href="/restaurants/sushi-sushi/">Sushi Sushi</a> Japanese, Sushi<br/> 54 Tiemann Pl | Btwn Claremont Ave &amp; Broadway   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "333625"' href="https://www.seamless.com/r/a/1124/menu/menupages/278462?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>japanese, sushi</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "342143"' href="/restaurants/insomnia-cookies-7/">Insomnia Cookies</a> Bakery &amp; Pastries, Desserts<br/> 1028 Amsterdam Ave | Btwn 110th &amp; 111th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "342143"' href="https://www.seamless.com/r/a/1124/menu/menupages/298599?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>bakery-pastries, desserts</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "349820"' href="/restaurants/cafe-amrita/">Cafe Amrita</a> Coffee &amp; Tea, Sandwiches<br/> 301 W 110th St | At 8th Ave  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "351970"' href="/restaurants/pinkberry-16/">Pinkberry</a> Desserts<br/> 2873 Broadway | Btwn 111th &amp; 112th St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>desserts</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "352331"' href="/restaurants/artopolis-espresso-cafe/">Artopolis Espresso Cafe</a> Coffee &amp; Tea, Sandwiches, Crepes<br/> 1090 Amsterdam Ave | Btwn 113th &amp; 114th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "352331"' href="https://www.seamless.com/r/a/1124/menu/menupages/287218?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea, sandwiches, crepes</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "353769"' href="/restaurants/max-caffe/">Max Caffe</a> Coffee &amp; Tea, Sandwiches<br/> 1262 Amsterdam Ave | Btwn 122nd &amp; 123rd St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "354422"' href="/restaurants/chipotle-27/">Chipotle</a> Mexican<br/> 2843 Broadway | At 110th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>mexican</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "357182"' href="/restaurants/chokolat-patisserie/">Chokolat Patisserie</a> Bakery &amp; Pastries, Desserts<br/> 3111 Broadway | Btwn 123rd &amp; La Salle St  </td> <td class="price"> <span class="price5">5</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>bakery-pastries, desserts</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "357467"' href="/restaurants/chokolat-patisserie-2/">Chokolat Patisserie</a> Bakery &amp; Pastries, Coffee &amp; Tea, Desserts<br/> 3187 Broadway | Btwn Tiemann Pl &amp; 125th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>bakery-pastries, coffee-tea, desserts</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "359466"' href="/restaurants/joes-g-h-deli/">Joe's G-H Deli</a> Deli Food, Sandwiches<br/> 3161 Broadway | Btwn Tiemann Pl &amp; La Salle St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>deli, sandwiches</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "359503"' href="/restaurants/joe-the-art-of-coffee-5/">Joe the Art of Coffee</a> Coffee &amp; Tea<br/> 550 W 120th St | Btwn Amsterdam Ave &amp; Broadway  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "359984"' href="/restaurants/levain-bakery-2/">Levain Bakery</a> Bakery &amp; Pastries, Desserts<br/> 2167 Frederick Douglas Blvd | Btwn 116th &amp; 117th St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>bakery-pastries, desserts</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "360444"' href="/restaurants/silvana/">Silvana</a> Middle Eastern, Vegetarian<br/> 300 W 116th St | At Fredrick Douglass Blvd   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "360444"' href="https://www.seamless.com/r/a/1124/menu/menupages/288774?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>middle-eastern, vegetarian</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "360644"' href="/restaurants/bier-international/">Bier International</a> German, Eclectic &amp; International, Bar Food<br/> 2099 Frederick Douglass Blvd | Btwn 113th &amp; 114th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "360644"' href="https://www.seamless.com/r/a/1124/menu/menupages/289506?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>german, eclectic, bar-food</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "360860"' href="/restaurants/vegenation/">Vegenation</a> Indian, Vegetarian<br/> 115th St &amp; Broadway   </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>indian, vegetarian</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "361028"' href="/restaurants/flat-top/">Flat Top</a> American (New), Bistro<br/> 1241 Amsterdam Ave | At 121st St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "361028"' href="https://www.seamless.com/r/a/1124/menu/menupages/316719?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price4">4</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american-new, bistro</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "363009"' href="/restaurants/kuro-kuma/">Kuro Kuma</a> Coffee &amp; Tea<br/> 3139 Broadway | At La Salle St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "364075"' href="/restaurants/vinateria/">Vinateria</a> American (New)<br/> 2221 Frederick Douglass Blvd | At 119th St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american-new</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "366197"' href="/restaurants/henan-cart/">Henan Cart</a> Chinese<br/> W 115th St | At Broadway  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>chinese</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "367497"' href="/restaurants/vine/">Vine</a> Japanese, Sushi, Thai<br/> 2953 Broadway | Btwn 115th &amp; 116th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "367497"' href="https://www.seamless.com/r/a/1124/menu/menupages/293742?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>japanese, sushi, thai</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "373592"' href="/restaurants/el-paso-truck/">El Paso Truck</a> Mexican<br/> Location Varies   </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>mexican</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "385035"' href="/restaurants/mamas-fried-chicken-and-pizza/">Mama's Fried Chicken and Pizza</a> Pizza, Chicken<br/> 2158 Frederick Douglas Blvd | Btwn W 116th &amp; W 117th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "385035"' href="https://www.seamless.com/r/a/1124/menu/menupages/314159?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>pizza, chicken</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "385052"' href="/restaurants/chapati-house/">Chapati House</a> Indian<br/> 3153 Broadway | Btwn Tiemann Pl &amp; La Salle St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "385052"' href="https://www.seamless.com/r/a/1124/menu/menupages/288817?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>indian</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "386888"' href="/restaurants/dig-inn-seasonal-market-7/">Dig Inn Seasonal Market</a> American, Local/Organic<br/> 2884 Broadway | Btwn 112th &amp; 113th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american, localorganic</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "389189"' href="/restaurants/uncle-luoyang/">Uncle Luoyang</a> Chinese<br/> 3010 Broadway | At W 119th St  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>chinese</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "389453"' href="/restaurants/pita-grill-10/">Pita Grill</a> Middle Eastern<br/> 1028 Amsterdam Ave | Btwn W 110th &amp; W 111th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "389453"' href="https://www.seamless.com/r/a/1124/menu/menupages/291068?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>middle-eastern</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "395723"' href="/restaurants/kissaten-jin/">Kissaten Jin</a> Japanese<br/> 3187 Broadway | At Tiemann Pl  </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>japanese</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "396021"' href="/restaurants/serengeti-teas-spices/">Serengeti Teas &amp; Spices</a> Coffee &amp; Tea, Teahouses<br/> 2292 Frederick Douglass Blvd | Btwn 123rd &amp; 124th St  </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>coffee-tea, teahouses</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "424341"' href="/restaurants/lighthouse-fish-market-restaurant/">Lighthouse Fish Market &amp; Restaurant</a> Seafood, Wings, Fish &amp; Chips<br/> 2451 Frederick Douglas Blvd | Btwn 131st &amp; 133rd St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "424341"' href="https://www.seamless.com/r/a/1124/menu/menupages/296959?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price3">3</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>seafood, wings, fish--chips</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "433793"' href="/restaurants/lolos-seafood-shack/">Lolo's Seafood Shack</a> Seafood<br/> 303 W 116th St | Btwn Manhattan Ave &amp; Frederick Douglass Blvd   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "433793"' href="https://www.seamless.com/r/a/1124/menu/menupages/299281?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>seafood</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "434620"' href="/restaurants/harmony/">Harmony</a> Sandwiches, Salads, Teahouses<br/> 390 Manhattan Ave | Btwn 116th &amp; 117th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "434620"' href="https://www.seamless.com/r/a/1124/menu/menupages/299338?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price1">1</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>sandwiches, salads, teahouses</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "475421"' href="/restaurants/bernheim-schwartz/">Bernheim &amp; Schwartz</a> American, Gastropub<br/> 2911 Broadway | Btwn W 113th &amp; 114th St   <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "475421"' href="https://www.seamless.com/r/a/1124/menu/menupages/303868?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> <span class="price2">2</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american, gastropub</td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "477304"' href="/restaurants/bth-restaurant-lounge/">BTH (By The Hudson)</a> American (New)<br/> 712 W 125th St | At Henry Hudson Pkwy  </td> <td class="price"> <span class="price3">3</span> </td> <td>uptown</td> <td>morningside-heights</td> <td>american-new</td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "485444"' href="/restaurants/empanadas-monumental-4/">Empanadas Monumental</a>  1344 Amsterdam Ave    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "485444"' href="https://www.seamless.com/r/a/1124/menu/menupages/309538?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "486129"' href="/restaurants/friedmans-3/">Friedman's</a>  1187 Amsterdam Ave    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "486129"' href="https://www.seamless.com/r/a/1124/menu/menupages/309656?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "490267"' href="/restaurants/176-presbyterian-deli/">176 Presbyterian Deli</a>  1317 St Nicholas Ave    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "490267"' href="https://www.seamless.com/r/a/1124/menu/menupages/314765?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "490608"' href="/restaurants/nacho-mamas-2/">Nacho Mama's</a>  1268 Amsterdam Ave    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "490608"' href="https://www.seamless.com/r/a/1124/menu/menupages/315749?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "490701"' href="/restaurants/streetbird-rotisserie/">Streetbird Rotisserie</a>  2149 Frederick Douglass Blvd    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "490701"' href="https://www.seamless.com/r/a/1124/menu/menupages/315939?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "490957"' href="/restaurants/colum-chinese-restaurant/">Colum Chinese Restaurant</a>  1034 Amsterdam Ave    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "490957"' href="https://www.seamless.com/r/a/1124/menu/menupages/316232?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "496904"' href="/restaurants/flacoz-tacoz-2/">Flacoz Tacoz</a>  1028 Amsterdam Ave    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "496904"' href="https://www.seamless.com/r/a/1124/menu/menupages/320600?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "497909"' href="/restaurants/sweetgreen-49/">sweetgreen</a>  2937 Broadway   </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>0</td></tr>
______________________

<tr> <td class="name-address" scope="row"> <a class="link search_result_link" data-clickstream="" data-cs-fires-on-click-link="clicked_searchresults" data-cs-with-property-text='masterlistid: "498418"' href="/restaurants/la-salle-dumpling-room/">La Salle Dumpling Room</a>  3141 Broadway    <div class="seamless-order-url_from_search_results"><a class="seamless-order-url" data-clickstream="" data-cs-fires-on-click-link="clicked_seamless-order-url_from_search_results" data-cs-with-property-text='city: New York, masterlistid: "498418"' href="https://www.seamless.com/r/a/1124/menu/menupages/321304?utm_source=menupages.com&amp;utm_medium=referral&amp;utm_campaign=order%20online" onclick="_gaq.push(['_trackEvent', 'Partner Link Clicks_Seamless', 'click_Search Results', '']);" target="_blank">Order From This Restaurant</a></div> </td> <td class="price"> N/A</td> <td>uptown</td> <td>morningside-heights</td> <td></td> <td>1</td></tr>
______________________


In [72]:
# Get the restaurant names

search_table = soup.find("table", {"class": "search-results"})
table_body = search_table.find("tbody")

for tr_tag in table_body.find_all('tr'):
    name_address_tag = tr_tag.find("td", {"class": "name-address"})
    a_tag = name_address_tag.find("a")
    print(a_tag.string)


Milano Market
Massawa
China Place
Subsconscious
Famous Famiglia
Kitchenette
V & T Pizza
New Aroma
Peking Garden
Tom's Restaurant
Pisticci
Deluxe
Toast
Tom's Delicious Pizza
West Place
Che' Bella Pizza
Ajanta
Panino Sportivo Roma
Max Soha
Strokos Pizza
Camille's
Amsterdam Restaurant
Nussbaum & Wu
Amir's Grill
M2M - Morning To Midnight
The Mill
Le Monde
Melba's
Chuck E Cheese's
Haagen-Dazs
Oren's
Dinosaur Bar-B-Que
Symposium Greek Restaurant
Koronet Pizza
The Heights Bar & Grill
Cafe Nana
Hamilton Deli
Community Food & Juice
Haakon's Hall
El Porton
Brad's
Mel's Burger Bar
Bettolona
Five Guys
Nikko
Falafel on Broadway
Sushi Sushi
Insomnia Cookies
Cafe Amrita
Pinkberry
Artopolis Espresso Cafe
Max Caffe
Chipotle
Chokolat Patisserie
Chokolat Patisserie
Joe's G-H Deli
Joe the Art of Coffee
Levain Bakery
Silvana
Bier International
Vegenation
Flat Top
Kuro Kuma
Vinateria
Henan Cart
Vine
El Paso Truck
Mama's Fried Chicken and Pizza
Chapati House
Dig Inn Seasonal Market
Uncle Luoyang
Pita Grill
Kissaten Jin
Serengeti Teas & Spices
Lighthouse Fish Market & Restaurant
Lolo's Seafood Shack
Harmony
Bernheim & Schwartz
BTH (By The Hudson)
Empanadas Monumental
Friedman's
176 Presbyterian Deli
Nacho Mama's
Streetbird Rotisserie
Colum Chinese Restaurant
Flacoz Tacoz
sweetgreen
La Salle Dumpling Room

In [73]:
# Getting names AND prices

search_table = soup.find("table", {"class": "search-results"})
table_body = search_table.find("tbody")

for tr_tag in table_body.find_all('tr'):
    
    # Get the restaurant name from the <a> inside a <td>
    name_address_tag = tr_tag.find("td", {"class": "name-address"})
    a_tag = name_address_tag.find("a")
    restaurant_name = a_tag.string
    
    # Get the price from <span> if present
    price_tag = tr_tag.find("td", {"class": "price"})
    price_span_tag = price_tag.find("span")
    if price_span_tag:
        price = int(price_span_tag.string)
    else:
        price = 0 #some of our restaurants don't have a span tag! 
    
    print(restaurant_name, price)


Milano Market 2
Massawa 0
China Place 0
Subsconscious 0
Famous Famiglia 0
Kitchenette 0
V & T Pizza 0
New Aroma 1
Peking Garden 1
Tom's Restaurant 1
Pisticci 1
Deluxe 1
Toast 2
Tom's Delicious Pizza 2
West Place 1
Che' Bella Pizza 0
Ajanta 0
Panino Sportivo Roma 2
Max Soha 2
Strokos Pizza 3
Camille's 1
Amsterdam Restaurant 1
Nussbaum & Wu 0
Amir's Grill 1
M2M - Morning To Midnight 1
The Mill 2
Le Monde 1
Melba's 1
Chuck E Cheese's 0
Haagen-Dazs 1
Oren's 0
Dinosaur Bar-B-Que 3
Symposium Greek Restaurant 0
Koronet Pizza 1
The Heights Bar & Grill 1
Cafe Nana 0
Hamilton Deli 0
Community Food & Juice 0
Haakon's Hall 0
El Porton 0
Brad's 1
Mel's Burger Bar 2
Bettolona 1
Five Guys 1
Nikko 2
Falafel on Broadway 1
Sushi Sushi 1
Insomnia Cookies 1
Cafe Amrita 1
Pinkberry 2
Artopolis Espresso Cafe 1
Max Caffe 2
Chipotle 1
Chokolat Patisserie 5
Chokolat Patisserie 1
Joe's G-H Deli 2
Joe the Art of Coffee 1
Levain Bakery 2
Silvana 1
Bier International 1
Vegenation 1
Flat Top 4
Kuro Kuma 1
Vinateria 2
Henan Cart 1
Vine 2
El Paso Truck 1
Mama's Fried Chicken and Pizza 1
Chapati House 2
Dig Inn Seasonal Market 1
Uncle Luoyang 1
Pita Grill 2
Kissaten Jin 1
Serengeti Teas & Spices 2
Lighthouse Fish Market & Restaurant 3
Lolo's Seafood Shack 2
Harmony 1
Bernheim & Schwartz 2
BTH (By The Hudson) 3
Empanadas Monumental 0
Friedman's 0
176 Presbyterian Deli 0
Nacho Mama's 0
Streetbird Rotisserie 0
Colum Chinese Restaurant 0
Flacoz Tacoz 0
sweetgreen 0
La Salle Dumpling Room 0

What if we wrote functions to help make our code more readable?

We're going to write this chunk of code in steps -- for complex tasks, it's a good idea to build incrementally.

Step 1: Writing a framework for our functions and some test code


In [74]:
# Write the framework of a function first and then

def get_name(tr_tag):
    return "TEST RESTAURANT"

def get_price(tag):
    return "999999"


# This code will allow us to TEST our functions! Our function frameworks return values of the right type. 

search_table = soup.find("table", {"class": "search-results"})
table_body = search_table.find("tbody")

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    
    print(restaurant_name, price) 
    
# Yay, it's bring what we told it to.


TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999
TEST RESTAURANT 999999

Step 2: Writing our get_names() function

Copying the code from our for loop


In [75]:
def get_name(tr_tag):
    name_address_tag = tr_tag.find("td", {"class": "name-address"})
    a_tag = name_address_tag.find("a")
    restaurant_name = a_tag.string
    return restaurant_name

def get_price(tag):
    return "999999"


# This code will allow us to TEST our functions! Our function frameworks return values of the right type. 

search_table = soup.find("table", {"class": "search-results"})
table_body = search_table.find("tbody")

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    
    print(restaurant_name, price)


Milano Market 999999
Massawa 999999
China Place 999999
Subsconscious 999999
Famous Famiglia 999999
Kitchenette 999999
V & T Pizza 999999
New Aroma 999999
Peking Garden 999999
Tom's Restaurant 999999
Pisticci 999999
Deluxe 999999
Toast 999999
Tom's Delicious Pizza 999999
West Place 999999
Che' Bella Pizza 999999
Ajanta 999999
Panino Sportivo Roma 999999
Max Soha 999999
Strokos Pizza 999999
Camille's 999999
Amsterdam Restaurant 999999
Nussbaum & Wu 999999
Amir's Grill 999999
M2M - Morning To Midnight 999999
The Mill 999999
Le Monde 999999
Melba's 999999
Chuck E Cheese's 999999
Haagen-Dazs 999999
Oren's 999999
Dinosaur Bar-B-Que 999999
Symposium Greek Restaurant 999999
Koronet Pizza 999999
The Heights Bar & Grill 999999
Cafe Nana 999999
Hamilton Deli 999999
Community Food & Juice 999999
Haakon's Hall 999999
El Porton 999999
Brad's 999999
Mel's Burger Bar 999999
Bettolona 999999
Five Guys 999999
Nikko 999999
Falafel on Broadway 999999
Sushi Sushi 999999
Insomnia Cookies 999999
Cafe Amrita 999999
Pinkberry 999999
Artopolis Espresso Cafe 999999
Max Caffe 999999
Chipotle 999999
Chokolat Patisserie 999999
Chokolat Patisserie 999999
Joe's G-H Deli 999999
Joe the Art of Coffee 999999
Levain Bakery 999999
Silvana 999999
Bier International 999999
Vegenation 999999
Flat Top 999999
Kuro Kuma 999999
Vinateria 999999
Henan Cart 999999
Vine 999999
El Paso Truck 999999
Mama's Fried Chicken and Pizza 999999
Chapati House 999999
Dig Inn Seasonal Market 999999
Uncle Luoyang 999999
Pita Grill 999999
Kissaten Jin 999999
Serengeti Teas & Spices 999999
Lighthouse Fish Market & Restaurant 999999
Lolo's Seafood Shack 999999
Harmony 999999
Bernheim & Schwartz 999999
BTH (By The Hudson) 999999
Empanadas Monumental 999999
Friedman's 999999
176 Presbyterian Deli 999999
Nacho Mama's 999999
Streetbird Rotisserie 999999
Colum Chinese Restaurant 999999
Flacoz Tacoz 999999
sweetgreen 999999
La Salle Dumpling Room 999999

Step 3: Writing our get_price() function

Again, just copying the code from our for loop


In [76]:
# Our functions:

def get_name(tr_tag):
    name_address_tag = tr_tag.find("td", {"class": "name-address"})
    a_tag = name_address_tag.find("a")
    restaurant_name = a_tag.string
    return restaurant_name

def get_price(tr_tag):
    price_tag = tr_tag.find("td", {"class": "price"})
    price_span_tag = price_tag.find("span")
    if price_span_tag:
        price = int(price_span_tag.string)
    else:
        price = 0 
    return price


# Looping through all the restaurants:

search_table = soup.find("table", {"class": "search-results"})
table_body = search_table.find("tbody")

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    
    print(restaurant_name, price)


Milano Market 2
Massawa 0
China Place 0
Subsconscious 0
Famous Famiglia 0
Kitchenette 0
V & T Pizza 0
New Aroma 1
Peking Garden 1
Tom's Restaurant 1
Pisticci 1
Deluxe 1
Toast 2
Tom's Delicious Pizza 2
West Place 1
Che' Bella Pizza 0
Ajanta 0
Panino Sportivo Roma 2
Max Soha 2
Strokos Pizza 3
Camille's 1
Amsterdam Restaurant 1
Nussbaum & Wu 0
Amir's Grill 1
M2M - Morning To Midnight 1
The Mill 2
Le Monde 1
Melba's 1
Chuck E Cheese's 0
Haagen-Dazs 1
Oren's 0
Dinosaur Bar-B-Que 3
Symposium Greek Restaurant 0
Koronet Pizza 1
The Heights Bar & Grill 1
Cafe Nana 0
Hamilton Deli 0
Community Food & Juice 0
Haakon's Hall 0
El Porton 0
Brad's 1
Mel's Burger Bar 2
Bettolona 1
Five Guys 1
Nikko 2
Falafel on Broadway 1
Sushi Sushi 1
Insomnia Cookies 1
Cafe Amrita 1
Pinkberry 2
Artopolis Espresso Cafe 1
Max Caffe 2
Chipotle 1
Chokolat Patisserie 5
Chokolat Patisserie 1
Joe's G-H Deli 2
Joe the Art of Coffee 1
Levain Bakery 2
Silvana 1
Bier International 1
Vegenation 1
Flat Top 4
Kuro Kuma 1
Vinateria 2
Henan Cart 1
Vine 2
El Paso Truck 1
Mama's Fried Chicken and Pizza 1
Chapati House 2
Dig Inn Seasonal Market 1
Uncle Luoyang 1
Pita Grill 2
Kissaten Jin 1
Serengeti Teas & Spices 2
Lighthouse Fish Market & Restaurant 3
Lolo's Seafood Shack 2
Harmony 1
Bernheim & Schwartz 2
BTH (By The Hudson) 3
Empanadas Monumental 0
Friedman's 0
176 Presbyterian Deli 0
Nacho Mama's 0
Streetbird Rotisserie 0
Colum Chinese Restaurant 0
Flacoz Tacoz 0
sweetgreen 0
La Salle Dumpling Room 0

Step 4: Setting up our get_cuisines() function

We're writing a dummy function just to test our code basically works.


In [77]:
def get_cuisines(tr_tag):
    # we want to return a list of strings
    
    # SOMEDAY HAVE GOOD CODE HERE
    
    # dummy return to test it
    return ['stuff', 'blah', 'etc']

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    cuisines = get_cuisines(tr_tag)
    
    print(restaurant_name, price, cuisines)


Milano Market 2 ['stuff', 'blah', 'etc']
Massawa 0 ['stuff', 'blah', 'etc']
China Place 0 ['stuff', 'blah', 'etc']
Subsconscious 0 ['stuff', 'blah', 'etc']
Famous Famiglia 0 ['stuff', 'blah', 'etc']
Kitchenette 0 ['stuff', 'blah', 'etc']
V & T Pizza 0 ['stuff', 'blah', 'etc']
New Aroma 1 ['stuff', 'blah', 'etc']
Peking Garden 1 ['stuff', 'blah', 'etc']
Tom's Restaurant 1 ['stuff', 'blah', 'etc']
Pisticci 1 ['stuff', 'blah', 'etc']
Deluxe 1 ['stuff', 'blah', 'etc']
Toast 2 ['stuff', 'blah', 'etc']
Tom's Delicious Pizza 2 ['stuff', 'blah', 'etc']
West Place 1 ['stuff', 'blah', 'etc']
Che' Bella Pizza 0 ['stuff', 'blah', 'etc']
Ajanta 0 ['stuff', 'blah', 'etc']
Panino Sportivo Roma 2 ['stuff', 'blah', 'etc']
Max Soha 2 ['stuff', 'blah', 'etc']
Strokos Pizza 3 ['stuff', 'blah', 'etc']
Camille's 1 ['stuff', 'blah', 'etc']
Amsterdam Restaurant 1 ['stuff', 'blah', 'etc']
Nussbaum & Wu 0 ['stuff', 'blah', 'etc']
Amir's Grill 1 ['stuff', 'blah', 'etc']
M2M - Morning To Midnight 1 ['stuff', 'blah', 'etc']
The Mill 2 ['stuff', 'blah', 'etc']
Le Monde 1 ['stuff', 'blah', 'etc']
Melba's 1 ['stuff', 'blah', 'etc']
Chuck E Cheese's 0 ['stuff', 'blah', 'etc']
Haagen-Dazs 1 ['stuff', 'blah', 'etc']
Oren's 0 ['stuff', 'blah', 'etc']
Dinosaur Bar-B-Que 3 ['stuff', 'blah', 'etc']
Symposium Greek Restaurant 0 ['stuff', 'blah', 'etc']
Koronet Pizza 1 ['stuff', 'blah', 'etc']
The Heights Bar & Grill 1 ['stuff', 'blah', 'etc']
Cafe Nana 0 ['stuff', 'blah', 'etc']
Hamilton Deli 0 ['stuff', 'blah', 'etc']
Community Food & Juice 0 ['stuff', 'blah', 'etc']
Haakon's Hall 0 ['stuff', 'blah', 'etc']
El Porton 0 ['stuff', 'blah', 'etc']
Brad's 1 ['stuff', 'blah', 'etc']
Mel's Burger Bar 2 ['stuff', 'blah', 'etc']
Bettolona 1 ['stuff', 'blah', 'etc']
Five Guys 1 ['stuff', 'blah', 'etc']
Nikko 2 ['stuff', 'blah', 'etc']
Falafel on Broadway 1 ['stuff', 'blah', 'etc']
Sushi Sushi 1 ['stuff', 'blah', 'etc']
Insomnia Cookies 1 ['stuff', 'blah', 'etc']
Cafe Amrita 1 ['stuff', 'blah', 'etc']
Pinkberry 2 ['stuff', 'blah', 'etc']
Artopolis Espresso Cafe 1 ['stuff', 'blah', 'etc']
Max Caffe 2 ['stuff', 'blah', 'etc']
Chipotle 1 ['stuff', 'blah', 'etc']
Chokolat Patisserie 5 ['stuff', 'blah', 'etc']
Chokolat Patisserie 1 ['stuff', 'blah', 'etc']
Joe's G-H Deli 2 ['stuff', 'blah', 'etc']
Joe the Art of Coffee 1 ['stuff', 'blah', 'etc']
Levain Bakery 2 ['stuff', 'blah', 'etc']
Silvana 1 ['stuff', 'blah', 'etc']
Bier International 1 ['stuff', 'blah', 'etc']
Vegenation 1 ['stuff', 'blah', 'etc']
Flat Top 4 ['stuff', 'blah', 'etc']
Kuro Kuma 1 ['stuff', 'blah', 'etc']
Vinateria 2 ['stuff', 'blah', 'etc']
Henan Cart 1 ['stuff', 'blah', 'etc']
Vine 2 ['stuff', 'blah', 'etc']
El Paso Truck 1 ['stuff', 'blah', 'etc']
Mama's Fried Chicken and Pizza 1 ['stuff', 'blah', 'etc']
Chapati House 2 ['stuff', 'blah', 'etc']
Dig Inn Seasonal Market 1 ['stuff', 'blah', 'etc']
Uncle Luoyang 1 ['stuff', 'blah', 'etc']
Pita Grill 2 ['stuff', 'blah', 'etc']
Kissaten Jin 1 ['stuff', 'blah', 'etc']
Serengeti Teas & Spices 2 ['stuff', 'blah', 'etc']
Lighthouse Fish Market & Restaurant 3 ['stuff', 'blah', 'etc']
Lolo's Seafood Shack 2 ['stuff', 'blah', 'etc']
Harmony 1 ['stuff', 'blah', 'etc']
Bernheim & Schwartz 2 ['stuff', 'blah', 'etc']
BTH (By The Hudson) 3 ['stuff', 'blah', 'etc']
Empanadas Monumental 0 ['stuff', 'blah', 'etc']
Friedman's 0 ['stuff', 'blah', 'etc']
176 Presbyterian Deli 0 ['stuff', 'blah', 'etc']
Nacho Mama's 0 ['stuff', 'blah', 'etc']
Streetbird Rotisserie 0 ['stuff', 'blah', 'etc']
Colum Chinese Restaurant 0 ['stuff', 'blah', 'etc']
Flacoz Tacoz 0 ['stuff', 'blah', 'etc']
sweetgreen 0 ['stuff', 'blah', 'etc']
La Salle Dumpling Room 0 ['stuff', 'blah', 'etc']

Step 5: Writing our get_cuisines() function


In [78]:
def get_cuisines(tr_tag):
    all_td_tags = tr_tag.find_all("td")
    cuisine_tag = all_td_tags[4]
    cuisines = cuisine_tag.string
    cuisines_list = cuisines.split(", ")
    return cuisines_list

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    cuisines = get_cuisines(tr_tag)
    
    print(restaurant_name, price, cuisines)
    
# We run into an error!


Milano Market 2 ['deli', 'sandwiches']
Massawa 0 ['ethiopian', 'african']
China Place 0 ['chinese', 'japanese', 'sushi']
Subsconscious 0 ['cheese-steaks', 'deli', 'sandwiches', 'salads']
Famous Famiglia 0 ['italian', 'pizza']
Kitchenette 0 ['bakery-pastries', 'american', 'desserts']
V & T Pizza 0 ['italian', 'pizza']
New Aroma 1 ['chinese']
Peking Garden 1 ['chinese']
Tom's Restaurant 1 ['diner']
Pisticci 1 ['italian']
Deluxe 1 ['diner', 'american']
Toast 2 ['american', 'bar-food']
Tom's Delicious Pizza 2 ['italian', 'pizza']
West Place 1 ['chinese']
Che' Bella Pizza 0 ['italian', 'pizza']
Ajanta 0 ['indian']
Panino Sportivo Roma 2 ['italian', 'coffee-tea', 'sandwiches']
Max Soha 2 ['italian']
Strokos Pizza 3 ['deli', 'pizza', 'sandwiches', 'chicken']
Camille's 1 ['american']
Amsterdam Restaurant 1 ['american-new', 'tapas']
Nussbaum & Wu 0 ['deli', 'sandwiches', 'bagels', 'salads']
Amir's Grill 1 ['middle-eastern']
M2M - Morning To Midnight 1 ['japanese', 'sushi', 'deli', 'sandwiches']
The Mill 2 ['korean']
Le Monde 1 ['french', 'bistro']
Melba's 1 ['american-new', 'soul-food']
Chuck E Cheese's 0 ['pizza', 'american']
Haagen-Dazs 1 ['desserts']
Oren's 0 ['coffee-tea', 'sandwiches']
Dinosaur Bar-B-Que 3 ['barbecue', 'soul-food']
Symposium Greek Restaurant 0 ['greek', 'vegetarian']
Koronet Pizza 1 ['pizza']
The Heights Bar & Grill 1 ['southwestern', 'tapas', 'bar-food']
Cafe Nana 0 ['middle-eastern', 'kosher']
Hamilton Deli 0 ['deli', 'sandwiches']
Community Food & Juice 0 ['american-new', 'smoothies-juices', 'vegetarian', 'healthy', 'localorganic']
Haakon's Hall 0 ['american', 'scandinavian']
El Porton 0 ['mexican']
Brad's 1 ['coffee-tea']
Mel's Burger Bar 2 ['burgers', 'bar-food']
Bettolona 1 ['italian', 'pizza', 'localorganic']
Five Guys 1 ['burgers', 'hot-dogs']
Nikko 2 ['chinese', 'japanese', 'sushi', 'teahouses']
Falafel on Broadway 1 ['middle-eastern']
Sushi Sushi 1 ['japanese', 'sushi']
Insomnia Cookies 1 ['bakery-pastries', 'desserts']
Cafe Amrita 1 ['coffee-tea', 'sandwiches']
Pinkberry 2 ['desserts']
Artopolis Espresso Cafe 1 ['coffee-tea', 'sandwiches', 'crepes']
Max Caffe 2 ['coffee-tea', 'sandwiches']
Chipotle 1 ['mexican']
Chokolat Patisserie 5 ['bakery-pastries', 'desserts']
Chokolat Patisserie 1 ['bakery-pastries', 'coffee-tea', 'desserts']
Joe's G-H Deli 2 ['deli', 'sandwiches']
Joe the Art of Coffee 1 ['coffee-tea']
Levain Bakery 2 ['bakery-pastries', 'desserts']
Silvana 1 ['middle-eastern', 'vegetarian']
Bier International 1 ['german', 'eclectic', 'bar-food']
Vegenation 1 ['indian', 'vegetarian']
Flat Top 4 ['american-new', 'bistro']
Kuro Kuma 1 ['coffee-tea']
Vinateria 2 ['american-new']
Henan Cart 1 ['chinese']
Vine 2 ['japanese', 'sushi', 'thai']
El Paso Truck 1 ['mexican']
Mama's Fried Chicken and Pizza 1 ['pizza', 'chicken']
Chapati House 2 ['indian']
Dig Inn Seasonal Market 1 ['american', 'localorganic']
Uncle Luoyang 1 ['chinese']
Pita Grill 2 ['middle-eastern']
Kissaten Jin 1 ['japanese']
Serengeti Teas & Spices 2 ['coffee-tea', 'teahouses']
Lighthouse Fish Market & Restaurant 3 ['seafood', 'wings', 'fish--chips']
Lolo's Seafood Shack 2 ['seafood']
Harmony 1 ['sandwiches', 'salads', 'teahouses']
Bernheim & Schwartz 2 ['american', 'gastropub']
BTH (By The Hudson) 3 ['american-new']
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-78-1c7b78535e5f> in <module>()
     10     restaurant_name = get_name(tr_tag)
     11     price = get_price(tr_tag)
---> 12     cuisines = get_cuisines(tr_tag)
     13 
     14     print(restaurant_name, price, cuisines)

<ipython-input-78-1c7b78535e5f> in get_cuisines(tr_tag)
      3     cuisine_tag = all_td_tags[4]
      4     cuisines = cuisine_tag.string
----> 5     cuisines_list = cuisines.split(", ")
      6     return cuisines_list
      7 

AttributeError: 'NoneType' object has no attribute 'split'

Step 6: Debugging our error with strategic print statements


In [79]:
def get_cuisines(tr_tag):
    all_td_tags = tr_tag.find_all("td")
    cuisine_tag = all_td_tags[4]
    print(cuisine_tag) # debugging strategy to see what is causing our code to break
    cuisines = cuisine_tag.string
    cuisines_list = cuisines.split(", ")
    return cuisines_list

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    print(restaurant_name) # debugging strategy to see what restaurant is causing our code to break
    cuisines = get_cuisines(tr_tag)
    
    print(restaurant_name, price, cuisines)
    
# sometimes of <td> tag is empty!


Milano Market
<td>deli, sandwiches</td>
Milano Market 2 ['deli', 'sandwiches']
Massawa
<td>ethiopian, african</td>
Massawa 0 ['ethiopian', 'african']
China Place
<td>chinese, japanese, sushi</td>
China Place 0 ['chinese', 'japanese', 'sushi']
Subsconscious
<td>cheese-steaks, deli, sandwiches, salads</td>
Subsconscious 0 ['cheese-steaks', 'deli', 'sandwiches', 'salads']
Famous Famiglia
<td>italian, pizza</td>
Famous Famiglia 0 ['italian', 'pizza']
Kitchenette
<td>bakery-pastries, american, desserts</td>
Kitchenette 0 ['bakery-pastries', 'american', 'desserts']
V & T Pizza
<td>italian, pizza</td>
V & T Pizza 0 ['italian', 'pizza']
New Aroma
<td>chinese</td>
New Aroma 1 ['chinese']
Peking Garden
<td>chinese</td>
Peking Garden 1 ['chinese']
Tom's Restaurant
<td>diner</td>
Tom's Restaurant 1 ['diner']
Pisticci
<td>italian</td>
Pisticci 1 ['italian']
Deluxe
<td>diner, american</td>
Deluxe 1 ['diner', 'american']
Toast
<td>american, bar-food</td>
Toast 2 ['american', 'bar-food']
Tom's Delicious Pizza
<td>italian, pizza</td>
Tom's Delicious Pizza 2 ['italian', 'pizza']
West Place
<td>chinese</td>
West Place 1 ['chinese']
Che' Bella Pizza
<td>italian, pizza</td>
Che' Bella Pizza 0 ['italian', 'pizza']
Ajanta
<td>indian</td>
Ajanta 0 ['indian']
Panino Sportivo Roma
<td>italian, coffee-tea, sandwiches</td>
Panino Sportivo Roma 2 ['italian', 'coffee-tea', 'sandwiches']
Max Soha
<td>italian</td>
Max Soha 2 ['italian']
Strokos Pizza
<td>deli, pizza, sandwiches, chicken</td>
Strokos Pizza 3 ['deli', 'pizza', 'sandwiches', 'chicken']
Camille's
<td>american</td>
Camille's 1 ['american']
Amsterdam Restaurant
<td>american-new, tapas</td>
Amsterdam Restaurant 1 ['american-new', 'tapas']
Nussbaum & Wu
<td>deli, sandwiches, bagels, salads</td>
Nussbaum & Wu 0 ['deli', 'sandwiches', 'bagels', 'salads']
Amir's Grill
<td>middle-eastern</td>
Amir's Grill 1 ['middle-eastern']
M2M - Morning To Midnight
<td>japanese, sushi, deli, sandwiches</td>
M2M - Morning To Midnight 1 ['japanese', 'sushi', 'deli', 'sandwiches']
The Mill
<td>korean</td>
The Mill 2 ['korean']
Le Monde
<td>french, bistro</td>
Le Monde 1 ['french', 'bistro']
Melba's
<td>american-new, soul-food</td>
Melba's 1 ['american-new', 'soul-food']
Chuck E Cheese's
<td>pizza, american</td>
Chuck E Cheese's 0 ['pizza', 'american']
Haagen-Dazs
<td>desserts</td>
Haagen-Dazs 1 ['desserts']
Oren's
<td>coffee-tea, sandwiches</td>
Oren's 0 ['coffee-tea', 'sandwiches']
Dinosaur Bar-B-Que
<td>barbecue, soul-food</td>
Dinosaur Bar-B-Que 3 ['barbecue', 'soul-food']
Symposium Greek Restaurant
<td>greek, vegetarian</td>
Symposium Greek Restaurant 0 ['greek', 'vegetarian']
Koronet Pizza
<td>pizza</td>
Koronet Pizza 1 ['pizza']
The Heights Bar & Grill
<td>southwestern, tapas, bar-food</td>
The Heights Bar & Grill 1 ['southwestern', 'tapas', 'bar-food']
Cafe Nana
<td>middle-eastern, kosher</td>
Cafe Nana 0 ['middle-eastern', 'kosher']
Hamilton Deli
<td>deli, sandwiches</td>
Hamilton Deli 0 ['deli', 'sandwiches']
Community Food & Juice
<td>american-new, smoothies-juices, vegetarian, healthy, localorganic</td>
Community Food & Juice 0 ['american-new', 'smoothies-juices', 'vegetarian', 'healthy', 'localorganic']
Haakon's Hall
<td>american, scandinavian</td>
Haakon's Hall 0 ['american', 'scandinavian']
El Porton
<td>mexican</td>
El Porton 0 ['mexican']
Brad's
<td>coffee-tea</td>
Brad's 1 ['coffee-tea']
Mel's Burger Bar
<td>burgers, bar-food</td>
Mel's Burger Bar 2 ['burgers', 'bar-food']
Bettolona
<td>italian, pizza, localorganic</td>
Bettolona 1 ['italian', 'pizza', 'localorganic']
Five Guys
<td>burgers, hot-dogs</td>
Five Guys 1 ['burgers', 'hot-dogs']
Nikko
<td>chinese, japanese, sushi, teahouses</td>
Nikko 2 ['chinese', 'japanese', 'sushi', 'teahouses']
Falafel on Broadway
<td>middle-eastern</td>
Falafel on Broadway 1 ['middle-eastern']
Sushi Sushi
<td>japanese, sushi</td>
Sushi Sushi 1 ['japanese', 'sushi']
Insomnia Cookies
<td>bakery-pastries, desserts</td>
Insomnia Cookies 1 ['bakery-pastries', 'desserts']
Cafe Amrita
<td>coffee-tea, sandwiches</td>
Cafe Amrita 1 ['coffee-tea', 'sandwiches']
Pinkberry
<td>desserts</td>
Pinkberry 2 ['desserts']
Artopolis Espresso Cafe
<td>coffee-tea, sandwiches, crepes</td>
Artopolis Espresso Cafe 1 ['coffee-tea', 'sandwiches', 'crepes']
Max Caffe
<td>coffee-tea, sandwiches</td>
Max Caffe 2 ['coffee-tea', 'sandwiches']
Chipotle
<td>mexican</td>
Chipotle 1 ['mexican']
Chokolat Patisserie
<td>bakery-pastries, desserts</td>
Chokolat Patisserie 5 ['bakery-pastries', 'desserts']
Chokolat Patisserie
<td>bakery-pastries, coffee-tea, desserts</td>
Chokolat Patisserie 1 ['bakery-pastries', 'coffee-tea', 'desserts']
Joe's G-H Deli
<td>deli, sandwiches</td>
Joe's G-H Deli 2 ['deli', 'sandwiches']
Joe the Art of Coffee
<td>coffee-tea</td>
Joe the Art of Coffee 1 ['coffee-tea']
Levain Bakery
<td>bakery-pastries, desserts</td>
Levain Bakery 2 ['bakery-pastries', 'desserts']
Silvana
<td>middle-eastern, vegetarian</td>
Silvana 1 ['middle-eastern', 'vegetarian']
Bier International
<td>german, eclectic, bar-food</td>
Bier International 1 ['german', 'eclectic', 'bar-food']
Vegenation
<td>indian, vegetarian</td>
Vegenation 1 ['indian', 'vegetarian']
Flat Top
<td>american-new, bistro</td>
Flat Top 4 ['american-new', 'bistro']
Kuro Kuma
<td>coffee-tea</td>
Kuro Kuma 1 ['coffee-tea']
Vinateria
<td>american-new</td>
Vinateria 2 ['american-new']
Henan Cart
<td>chinese</td>
Henan Cart 1 ['chinese']
Vine
<td>japanese, sushi, thai</td>
Vine 2 ['japanese', 'sushi', 'thai']
El Paso Truck
<td>mexican</td>
El Paso Truck 1 ['mexican']
Mama's Fried Chicken and Pizza
<td>pizza, chicken</td>
Mama's Fried Chicken and Pizza 1 ['pizza', 'chicken']
Chapati House
<td>indian</td>
Chapati House 2 ['indian']
Dig Inn Seasonal Market
<td>american, localorganic</td>
Dig Inn Seasonal Market 1 ['american', 'localorganic']
Uncle Luoyang
<td>chinese</td>
Uncle Luoyang 1 ['chinese']
Pita Grill
<td>middle-eastern</td>
Pita Grill 2 ['middle-eastern']
Kissaten Jin
<td>japanese</td>
Kissaten Jin 1 ['japanese']
Serengeti Teas & Spices
<td>coffee-tea, teahouses</td>
Serengeti Teas & Spices 2 ['coffee-tea', 'teahouses']
Lighthouse Fish Market & Restaurant
<td>seafood, wings, fish--chips</td>
Lighthouse Fish Market & Restaurant 3 ['seafood', 'wings', 'fish--chips']
Lolo's Seafood Shack
<td>seafood</td>
Lolo's Seafood Shack 2 ['seafood']
Harmony
<td>sandwiches, salads, teahouses</td>
Harmony 1 ['sandwiches', 'salads', 'teahouses']
Bernheim & Schwartz
<td>american, gastropub</td>
Bernheim & Schwartz 2 ['american', 'gastropub']
BTH (By The Hudson)
<td>american-new</td>
BTH (By The Hudson) 3 ['american-new']
Empanadas Monumental
<td></td>
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-79-91a3e2306009> in <module>()
     12     price = get_price(tr_tag)
     13     print(restaurant_name) # debugging strategy to see what restaurant is causing our code to break
---> 14     cuisines = get_cuisines(tr_tag)
     15 
     16     print(restaurant_name, price, cuisines)

<ipython-input-79-91a3e2306009> in get_cuisines(tr_tag)
      4     print(cuisine_tag) # debugging strategy to see what is causing our code to break
      5     cuisines = cuisine_tag.string
----> 6     cuisines_list = cuisines.split(", ")
      7     return cuisines_list
      8 

AttributeError: 'NoneType' object has no attribute 'split'

Step 7: Correcting get_cuisines() function with if/else condition for NoneTypes


In [80]:
def get_cuisines(tr_tag):
    all_td_tags = tr_tag.find_all("td")
    cuisine_tag = all_td_tags[4]
    cuisines = cuisine_tag.string
    
    if cuisines:
        cuisines_list = cuisines.split(", ")
    else:
        cuisines_list = []
    return cuisines_list

for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    cuisines = get_cuisines(tr_tag)
    
    print(restaurant_name, price, cuisines)
    
# Woohoo, everything prints like we'd want it to!


Milano Market 2 ['deli', 'sandwiches']
Massawa 0 ['ethiopian', 'african']
China Place 0 ['chinese', 'japanese', 'sushi']
Subsconscious 0 ['cheese-steaks', 'deli', 'sandwiches', 'salads']
Famous Famiglia 0 ['italian', 'pizza']
Kitchenette 0 ['bakery-pastries', 'american', 'desserts']
V & T Pizza 0 ['italian', 'pizza']
New Aroma 1 ['chinese']
Peking Garden 1 ['chinese']
Tom's Restaurant 1 ['diner']
Pisticci 1 ['italian']
Deluxe 1 ['diner', 'american']
Toast 2 ['american', 'bar-food']
Tom's Delicious Pizza 2 ['italian', 'pizza']
West Place 1 ['chinese']
Che' Bella Pizza 0 ['italian', 'pizza']
Ajanta 0 ['indian']
Panino Sportivo Roma 2 ['italian', 'coffee-tea', 'sandwiches']
Max Soha 2 ['italian']
Strokos Pizza 3 ['deli', 'pizza', 'sandwiches', 'chicken']
Camille's 1 ['american']
Amsterdam Restaurant 1 ['american-new', 'tapas']
Nussbaum & Wu 0 ['deli', 'sandwiches', 'bagels', 'salads']
Amir's Grill 1 ['middle-eastern']
M2M - Morning To Midnight 1 ['japanese', 'sushi', 'deli', 'sandwiches']
The Mill 2 ['korean']
Le Monde 1 ['french', 'bistro']
Melba's 1 ['american-new', 'soul-food']
Chuck E Cheese's 0 ['pizza', 'american']
Haagen-Dazs 1 ['desserts']
Oren's 0 ['coffee-tea', 'sandwiches']
Dinosaur Bar-B-Que 3 ['barbecue', 'soul-food']
Symposium Greek Restaurant 0 ['greek', 'vegetarian']
Koronet Pizza 1 ['pizza']
The Heights Bar & Grill 1 ['southwestern', 'tapas', 'bar-food']
Cafe Nana 0 ['middle-eastern', 'kosher']
Hamilton Deli 0 ['deli', 'sandwiches']
Community Food & Juice 0 ['american-new', 'smoothies-juices', 'vegetarian', 'healthy', 'localorganic']
Haakon's Hall 0 ['american', 'scandinavian']
El Porton 0 ['mexican']
Brad's 1 ['coffee-tea']
Mel's Burger Bar 2 ['burgers', 'bar-food']
Bettolona 1 ['italian', 'pizza', 'localorganic']
Five Guys 1 ['burgers', 'hot-dogs']
Nikko 2 ['chinese', 'japanese', 'sushi', 'teahouses']
Falafel on Broadway 1 ['middle-eastern']
Sushi Sushi 1 ['japanese', 'sushi']
Insomnia Cookies 1 ['bakery-pastries', 'desserts']
Cafe Amrita 1 ['coffee-tea', 'sandwiches']
Pinkberry 2 ['desserts']
Artopolis Espresso Cafe 1 ['coffee-tea', 'sandwiches', 'crepes']
Max Caffe 2 ['coffee-tea', 'sandwiches']
Chipotle 1 ['mexican']
Chokolat Patisserie 5 ['bakery-pastries', 'desserts']
Chokolat Patisserie 1 ['bakery-pastries', 'coffee-tea', 'desserts']
Joe's G-H Deli 2 ['deli', 'sandwiches']
Joe the Art of Coffee 1 ['coffee-tea']
Levain Bakery 2 ['bakery-pastries', 'desserts']
Silvana 1 ['middle-eastern', 'vegetarian']
Bier International 1 ['german', 'eclectic', 'bar-food']
Vegenation 1 ['indian', 'vegetarian']
Flat Top 4 ['american-new', 'bistro']
Kuro Kuma 1 ['coffee-tea']
Vinateria 2 ['american-new']
Henan Cart 1 ['chinese']
Vine 2 ['japanese', 'sushi', 'thai']
El Paso Truck 1 ['mexican']
Mama's Fried Chicken and Pizza 1 ['pizza', 'chicken']
Chapati House 2 ['indian']
Dig Inn Seasonal Market 1 ['american', 'localorganic']
Uncle Luoyang 1 ['chinese']
Pita Grill 2 ['middle-eastern']
Kissaten Jin 1 ['japanese']
Serengeti Teas & Spices 2 ['coffee-tea', 'teahouses']
Lighthouse Fish Market & Restaurant 3 ['seafood', 'wings', 'fish--chips']
Lolo's Seafood Shack 2 ['seafood']
Harmony 1 ['sandwiches', 'salads', 'teahouses']
Bernheim & Schwartz 2 ['american', 'gastropub']
BTH (By The Hudson) 3 ['american-new']
Empanadas Monumental 0 []
Friedman's 0 []
176 Presbyterian Deli 0 []
Nacho Mama's 0 []
Streetbird Rotisserie 0 []
Colum Chinese Restaurant 0 []
Flacoz Tacoz 0 []
sweetgreen 0 []
La Salle Dumpling Room 0 []

Step 8: Saving our data to a list of dictionaries

We want to do more than just print! The data structure of a list of dictionaries is pretty flexible -- we can go to a pandas DataFrame, a csv, and someday, a SQL table from there.


In [152]:
restaurants = []
for tr_tag in table_body.find_all('tr'):
    
    restaurant_name = get_name(tr_tag)
    price = get_price(tr_tag)
    cuisines = get_cuisines(tr_tag)
    
    rest_dict = {'name': restaurant_name, 'price': int(price), 'cuisines': cuisines}
    restaurants.append(rest_dict)
    
restaurants


Out[152]:
[{'cuisines': ['deli', 'sandwiches'], 'name': 'Milano Market', 'price': 2},
 {'cuisines': ['ethiopian', 'african'], 'name': 'Massawa', 'price': 0},
 {'cuisines': ['chinese', 'japanese', 'sushi'],
  'name': 'China Place',
  'price': 0},
 {'cuisines': ['cheese-steaks', 'deli', 'sandwiches', 'salads'],
  'name': 'Subsconscious',
  'price': 0},
 {'cuisines': ['italian', 'pizza'], 'name': 'Famous Famiglia', 'price': 0},
 {'cuisines': ['bakery-pastries', 'american', 'desserts'],
  'name': 'Kitchenette',
  'price': 0},
 {'cuisines': ['italian', 'pizza'], 'name': 'V & T Pizza', 'price': 0},
 {'cuisines': ['chinese'], 'name': 'New Aroma', 'price': 1},
 {'cuisines': ['chinese'], 'name': 'Peking Garden', 'price': 1},
 {'cuisines': ['diner'], 'name': "Tom's Restaurant", 'price': 1},
 {'cuisines': ['italian'], 'name': 'Pisticci', 'price': 1},
 {'cuisines': ['diner', 'american'], 'name': 'Deluxe', 'price': 1},
 {'cuisines': ['american', 'bar-food'], 'name': 'Toast', 'price': 2},
 {'cuisines': ['italian', 'pizza'],
  'name': "Tom's Delicious Pizza",
  'price': 2},
 {'cuisines': ['chinese'], 'name': 'West Place', 'price': 1},
 {'cuisines': ['italian', 'pizza'], 'name': "Che' Bella Pizza", 'price': 0},
 {'cuisines': ['indian'], 'name': 'Ajanta', 'price': 0},
 {'cuisines': ['italian', 'coffee-tea', 'sandwiches'],
  'name': 'Panino Sportivo Roma',
  'price': 2},
 {'cuisines': ['italian'], 'name': 'Max Soha', 'price': 2},
 {'cuisines': ['deli', 'pizza', 'sandwiches', 'chicken'],
  'name': 'Strokos Pizza',
  'price': 3},
 {'cuisines': ['american'], 'name': "Camille's", 'price': 1},
 {'cuisines': ['american-new', 'tapas'],
  'name': 'Amsterdam Restaurant',
  'price': 1},
 {'cuisines': ['deli', 'sandwiches', 'bagels', 'salads'],
  'name': 'Nussbaum & Wu',
  'price': 0},
 {'cuisines': ['middle-eastern'], 'name': "Amir's Grill", 'price': 1},
 {'cuisines': ['japanese', 'sushi', 'deli', 'sandwiches'],
  'name': 'M2M - Morning To Midnight',
  'price': 1},
 {'cuisines': ['korean'], 'name': 'The Mill', 'price': 2},
 {'cuisines': ['french', 'bistro'], 'name': 'Le Monde', 'price': 1},
 {'cuisines': ['american-new', 'soul-food'], 'name': "Melba's", 'price': 1},
 {'cuisines': ['pizza', 'american'], 'name': "Chuck E Cheese's", 'price': 0},
 {'cuisines': ['desserts'], 'name': 'Haagen-Dazs', 'price': 1},
 {'cuisines': ['coffee-tea', 'sandwiches'], 'name': "Oren's", 'price': 0},
 {'cuisines': ['barbecue', 'soul-food'],
  'name': 'Dinosaur Bar-B-Que',
  'price': 3},
 {'cuisines': ['greek', 'vegetarian'],
  'name': 'Symposium Greek Restaurant',
  'price': 0},
 {'cuisines': ['pizza'], 'name': 'Koronet Pizza', 'price': 1},
 {'cuisines': ['southwestern', 'tapas', 'bar-food'],
  'name': 'The Heights Bar & Grill',
  'price': 1},
 {'cuisines': ['middle-eastern', 'kosher'], 'name': 'Cafe Nana', 'price': 0},
 {'cuisines': ['deli', 'sandwiches'], 'name': 'Hamilton Deli', 'price': 0},
 {'cuisines': ['american-new',
   'smoothies-juices',
   'vegetarian',
   'healthy',
   'localorganic'],
  'name': 'Community Food & Juice',
  'price': 0},
 {'cuisines': ['american', 'scandinavian'],
  'name': "Haakon's Hall",
  'price': 0},
 {'cuisines': ['mexican'], 'name': 'El Porton', 'price': 0},
 {'cuisines': ['coffee-tea'], 'name': "Brad's", 'price': 1},
 {'cuisines': ['burgers', 'bar-food'], 'name': "Mel's Burger Bar", 'price': 2},
 {'cuisines': ['italian', 'pizza', 'localorganic'],
  'name': 'Bettolona',
  'price': 1},
 {'cuisines': ['burgers', 'hot-dogs'], 'name': 'Five Guys', 'price': 1},
 {'cuisines': ['chinese', 'japanese', 'sushi', 'teahouses'],
  'name': 'Nikko',
  'price': 2},
 {'cuisines': ['middle-eastern'], 'name': 'Falafel on Broadway', 'price': 1},
 {'cuisines': ['japanese', 'sushi'], 'name': 'Sushi Sushi', 'price': 1},
 {'cuisines': ['bakery-pastries', 'desserts'],
  'name': 'Insomnia Cookies',
  'price': 1},
 {'cuisines': ['coffee-tea', 'sandwiches'], 'name': 'Cafe Amrita', 'price': 1},
 {'cuisines': ['desserts'], 'name': 'Pinkberry', 'price': 2},
 {'cuisines': ['coffee-tea', 'sandwiches', 'crepes'],
  'name': 'Artopolis Espresso Cafe',
  'price': 1},
 {'cuisines': ['coffee-tea', 'sandwiches'], 'name': 'Max Caffe', 'price': 2},
 {'cuisines': ['mexican'], 'name': 'Chipotle', 'price': 1},
 {'cuisines': ['bakery-pastries', 'desserts'],
  'name': 'Chokolat Patisserie',
  'price': 5},
 {'cuisines': ['bakery-pastries', 'coffee-tea', 'desserts'],
  'name': 'Chokolat Patisserie',
  'price': 1},
 {'cuisines': ['deli', 'sandwiches'], 'name': "Joe's G-H Deli", 'price': 2},
 {'cuisines': ['coffee-tea'], 'name': 'Joe the Art of Coffee', 'price': 1},
 {'cuisines': ['bakery-pastries', 'desserts'],
  'name': 'Levain Bakery',
  'price': 2},
 {'cuisines': ['middle-eastern', 'vegetarian'], 'name': 'Silvana', 'price': 1},
 {'cuisines': ['german', 'eclectic', 'bar-food'],
  'name': 'Bier International',
  'price': 1},
 {'cuisines': ['indian', 'vegetarian'], 'name': 'Vegenation', 'price': 1},
 {'cuisines': ['american-new', 'bistro'], 'name': 'Flat Top', 'price': 4},
 {'cuisines': ['coffee-tea'], 'name': 'Kuro Kuma', 'price': 1},
 {'cuisines': ['american-new'], 'name': 'Vinateria', 'price': 2},
 {'cuisines': ['chinese'], 'name': 'Henan Cart', 'price': 1},
 {'cuisines': ['japanese', 'sushi', 'thai'], 'name': 'Vine', 'price': 2},
 {'cuisines': ['mexican'], 'name': 'El Paso Truck', 'price': 1},
 {'cuisines': ['pizza', 'chicken'],
  'name': "Mama's Fried Chicken and Pizza",
  'price': 1},
 {'cuisines': ['indian'], 'name': 'Chapati House', 'price': 2},
 {'cuisines': ['american', 'localorganic'],
  'name': 'Dig Inn Seasonal Market',
  'price': 1},
 {'cuisines': ['chinese'], 'name': 'Uncle Luoyang', 'price': 1},
 {'cuisines': ['middle-eastern'], 'name': 'Pita Grill', 'price': 2},
 {'cuisines': ['japanese'], 'name': 'Kissaten Jin', 'price': 1},
 {'cuisines': ['coffee-tea', 'teahouses'],
  'name': 'Serengeti Teas & Spices',
  'price': 2},
 {'cuisines': ['seafood', 'wings', 'fish--chips'],
  'name': 'Lighthouse Fish Market & Restaurant',
  'price': 3},
 {'cuisines': ['seafood'], 'name': "Lolo's Seafood Shack", 'price': 2},
 {'cuisines': ['sandwiches', 'salads', 'teahouses'],
  'name': 'Harmony',
  'price': 1},
 {'cuisines': ['american', 'gastropub'],
  'name': 'Bernheim & Schwartz',
  'price': 2},
 {'cuisines': ['american-new'], 'name': 'BTH (By The Hudson)', 'price': 3},
 {'cuisines': [], 'name': 'Empanadas Monumental', 'price': 0},
 {'cuisines': [], 'name': "Friedman's", 'price': 0},
 {'cuisines': [], 'name': '176 Presbyterian Deli', 'price': 0},
 {'cuisines': [], 'name': "Nacho Mama's", 'price': 0},
 {'cuisines': [], 'name': 'Streetbird Rotisserie', 'price': 0},
 {'cuisines': [], 'name': 'Colum Chinese Restaurant', 'price': 0},
 {'cuisines': [], 'name': 'Flacoz Tacoz', 'price': 0},
 {'cuisines': [], 'name': 'sweetgreen', 'price': 0},
 {'cuisines': [], 'name': 'La Salle Dumpling Room', 'price': 0}]

Step 9: pandas DataFrame!


In [85]:
import pandas as pd
df = pd.DataFrame(restaurants)

In [86]:
df


Out[86]:
cuisines name price
0 [deli, sandwiches] Milano Market 2
1 [ethiopian, african] Massawa 0
2 [chinese, japanese, sushi] China Place 0
3 [cheese-steaks, deli, sandwiches, salads] Subsconscious 0
4 [italian, pizza] Famous Famiglia 0
5 [bakery-pastries, american, desserts] Kitchenette 0
6 [italian, pizza] V & T Pizza 0
7 [chinese] New Aroma 1
8 [chinese] Peking Garden 1
9 [diner] Tom's Restaurant 1
10 [italian] Pisticci 1
11 [diner, american] Deluxe 1
12 [american, bar-food] Toast 2
13 [italian, pizza] Tom's Delicious Pizza 2
14 [chinese] West Place 1
15 [italian, pizza] Che' Bella Pizza 0
16 [indian] Ajanta 0
17 [italian, coffee-tea, sandwiches] Panino Sportivo Roma 2
18 [italian] Max Soha 2
19 [deli, pizza, sandwiches, chicken] Strokos Pizza 3
20 [american] Camille's 1
21 [american-new, tapas] Amsterdam Restaurant 1
22 [deli, sandwiches, bagels, salads] Nussbaum & Wu 0
23 [middle-eastern] Amir's Grill 1
24 [japanese, sushi, deli, sandwiches] M2M - Morning To Midnight 1
25 [korean] The Mill 2
26 [french, bistro] Le Monde 1
27 [american-new, soul-food] Melba's 1
28 [pizza, american] Chuck E Cheese's 0
29 [desserts] Haagen-Dazs 1
... ... ... ...
58 [middle-eastern, vegetarian] Silvana 1
59 [german, eclectic, bar-food] Bier International 1
60 [indian, vegetarian] Vegenation 1
61 [american-new, bistro] Flat Top 4
62 [coffee-tea] Kuro Kuma 1
63 [american-new] Vinateria 2
64 [chinese] Henan Cart 1
65 [japanese, sushi, thai] Vine 2
66 [mexican] El Paso Truck 1
67 [pizza, chicken] Mama's Fried Chicken and Pizza 1
68 [indian] Chapati House 2
69 [american, localorganic] Dig Inn Seasonal Market 1
70 [chinese] Uncle Luoyang 1
71 [middle-eastern] Pita Grill 2
72 [japanese] Kissaten Jin 1
73 [coffee-tea, teahouses] Serengeti Teas & Spices 2
74 [seafood, wings, fish--chips] Lighthouse Fish Market & Restaurant 3
75 [seafood] Lolo's Seafood Shack 2
76 [sandwiches, salads, teahouses] Harmony 1
77 [american, gastropub] Bernheim & Schwartz 2
78 [american-new] BTH (By The Hudson) 3
79 [] Empanadas Monumental 0
80 [] Friedman's 0
81 [] 176 Presbyterian Deli 0
82 [] Nacho Mama's 0
83 [] Streetbird Rotisserie 0
84 [] Colum Chinese Restaurant 0
85 [] Flacoz Tacoz 0
86 [] sweetgreen 0
87 [] La Salle Dumpling Room 0

88 rows × 3 columns

putting this into SQL

"schema" ---> designing the tables

  • what tables do we need
  • what should those table have in them? (Columns and data types)

why we need more than one table? The way how relational data works. You have restaurants that has more than one cousine. We want to be able to able to do data normalization, which is a term use in relational data base. Its about separate data so any piece of data only appears one time.

"entities" ---> the thing you are storing

  • first entitiy = restaurants: name, price and a list of cusines
  • second entitity = which cuisines a restaurant is associeted

Restaurant table: id {unique integer identifying the restaurant} name string wirh restaurant name price integer that correspoonds to the number of dollar sings kind string that identifies the cuisines type itself

cuisines table: restaurant_id number associated with the restaurant)

kind

Sample entry from restaurant table id: 4 name: brad's

price: 1

sample entry from cuisines table restaurant_id: 4

kind: coffee_tea

restaurant_id:4 kind: seafood

"setup phae" creating database and creating tables "one time" --> psql "working with data phase" --> inserting records, selecting stuff ---> python

sql data types like

  • int integers
  • varchar(n) strring with lengt n
  • numeric number/decimal
  • "serial" -> integer that is automatically assigned

Connect to the database


In [139]:
import pg8000
conn = pg8000.connect(database="menupages")

In [140]:
type(conn)


Out[140]:
pg8000.core.Connection

In [163]:
conn.rollback() #execute this whenever toy make a SQL problem

In [142]:
cursor = conn.cursor()

cursor objects:

  • execute() <-- execute a SQL statement
  • fetchone() <--- fetches the first recrod of the results of a statement (as list)
  • fetchall() <---- returns all the rowes of the result of a statement( as a list of lists)

In [119]:
cursor.execute("INSERT INTO restaurant (name, price) VALUES ('good Food Places', 3)")
conn.commit()

In [120]:
cursor.execute("select * from restaurant")
for item in cursor.fetchall():
    print(item)


[2, 'Panino Sportivo Roma', 2]
[3, 'Max Soha', 2]
[4, 'good Food Places', 3]
[5, 'good Food Places', 3]
[6, 'Palace of Vegan Nosh', 3]
[7, 'Palace of Vegan Nosh', 3]
[8, 'good Food Places', 3]

In [121]:
cursor.execute("INSERT INTO restaurant (name, price) VALUES ('Palace of Vegan Nosh', 3) returning id")
results = cursor.fetchone()
conn.commit()

In [122]:
results


Out[122]:
[9]

In [123]:
rowld = results[0]

In [124]:
rowld


Out[124]:
9

Quoting and parameters in SQL


In [125]:
#WILL NOT WORK
cursor.execute("INSERT INTO restaurant (name, price) VALUES ('Brad's', 3) returning id")
results = cursor.fetchone()[0]
conn.commit()


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/pg8000/core.py in execute(self, cursor, operation, vals)
   1896         try:
-> 1897             ps = cache['ps'][key]
   1898             cursor.ps = ps

KeyError: ("INSERT INTO restaurant (name, price) VALUES ('Brad's', 3) returning id", ())

During handling of the above exception, another exception occurred:

ProgrammingError                          Traceback (most recent call last)
<ipython-input-125-4906bbc0b15f> in <module>()
----> 1 cursor.execute("INSERT INTO restaurant (name, price) VALUES ('Brad's', 3) returning id")
      2 results = cursor.fetchone()[0]
      3 conn.commit()

/usr/local/lib/python3.5/site-packages/pg8000/core.py in execute(self, operation, args, stream)
    905                 if not self._c.in_transaction and not self._c.autocommit:
    906                     self._c.execute(self, "begin transaction", None)
--> 907                 self._c.execute(self, operation, args)
    908         except AttributeError as e:
    909             if self._c is None:

/usr/local/lib/python3.5/site-packages/pg8000/core.py in execute(self, cursor, operation, vals)
   1944                 raise OperationalError(str(e))
   1945 
-> 1946             self.handle_messages(cursor)
   1947 
   1948             # We've got row_desc that allows us to identify what we're

/usr/local/lib/python3.5/site-packages/pg8000/core.py in handle_messages(self, cursor)
   2092 
   2093         if self.error is not None:
-> 2094             raise self.error
   2095 
   2096     # Byte1('C') - Identifies the message as a close command.

ProgrammingError: ('ERROR', '42601', 'syntax error at or near "s"', '52', 'scan.l', '1081', 'scanner_yyerror', '', '')

In [ ]:
#SQL injection attack
restaurant = "'Restaurant'); Delete from restaurant;"
string in python --> "quote" "escape" ---> valid sql statement
#very weird difficult and arquade

In [147]:
rest_insert = "INSERT INTO restaurant (name, price) VALUES (%s, %s)"
cursor.execute(rest_insert, ["Brad's", 1])
# pg8000 does the work: "INSERT INTOrestaurant (name, price) values ('Brad\'\'s', 1)"
conn.commit()

Insert a restaurant and its cuisines!!


In [144]:
cursor.execute("insert into restaurant (name, price) values (%s, %s) returning id", ["Test Restaurant", 2])
rowid = cursor.fetchone()[0]
conn.commit()

In [146]:
#let's say Test Restaunrant servers fondue and casseroles
cuisine_insert = "insert into cuisine (restaurant_id, kind) values (%s, %s)"
cursor.execute(cuisine_insert, [rowid, "fondue"])
cursor.execute(cuisine_insert, [rowid, 'casseroles'])
conn.commit


Out[146]:
<bound method Connection.commit of <pg8000.core.Connection object at 0x1073b9908>>

Insert many restaurants!!


In [150]:
rest_insert = "insert into restaurant (name, price) values (%s, %s)"
for item in restaurants:
    #execute sql statement with data from the restaurant!
    cursor.execute(rest_insert, [item['name'], item['price']])
conn.commit


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/pg8000/core.py in make_params(self, values)
   1854             try:
-> 1855                 params.append(self.py_types[typ])
   1856             except KeyError:

KeyError: <class 'bs4.element.NavigableString'>

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/pg8000/core.py in make_params(self, values)
   1857                 try:
-> 1858                     params.append(self.inspect_funcs[typ](value))
   1859                 except KeyError as e:

KeyError: <class 'bs4.element.NavigableString'>

During handling of the above exception, another exception occurred:

NotSupportedError                         Traceback (most recent call last)
<ipython-input-150-8f56fb39b1f8> in <module>()
      2 for item in restaurants:
      3     #execute sql statement with data from the restaurant!
----> 4     cursor.execute(rest_insert, [item['name'], item['price']])
      5 conn.commit

/usr/local/lib/python3.5/site-packages/pg8000/core.py in execute(self, operation, args, stream)
    905                 if not self._c.in_transaction and not self._c.autocommit:
    906                     self._c.execute(self, "begin transaction", None)
--> 907                 self._c.execute(self, operation, args)
    908         except AttributeError as e:
    909             if self._c is None:

/usr/local/lib/python3.5/site-packages/pg8000/core.py in execute(self, cursor, operation, vals)
   1891 
   1892         args = make_args(vals)
-> 1893         params = self.make_params(args)
   1894         key = operation, params
   1895 

/usr/local/lib/python3.5/site-packages/pg8000/core.py in make_params(self, values)
   1859                 except KeyError as e:
   1860                     raise NotSupportedError(
-> 1861                         "type " + str(e) + "not mapped to pg type")
   1862         return tuple(params)
   1863 

NotSupportedError: type <class 'bs4.element.NavigableString'>not mapped to pg type

In [153]:
first = restaurants[0]
first


Out[153]:
{'cuisines': ['deli', 'sandwiches'], 'name': 'Milano Market', 'price': 2}

In [154]:
print(first ['name'])


Milano Market

In [155]:
type(first['name'])


Out[155]:
bs4.element.NavigableString

why isnt this just a string?

wheneever you use the .string atribute of a Beuatiful soup tag objects, the type of that value is bs4.element.navigableString. fortunately, there is an easy fix: str(val)


In [157]:
rest_insert = "insert into restaurant (name, price) values (%s, %s)"
for item in restaurants:
    #execute sql statement with data from the restaurant!
    cursor.execute(rest_insert, [str(item['name']), item['price']])
conn.commit()

In [158]:
cursor.execute("insert into restaurant (name, price) values (%s, %s) returning id", ["Test Restaurant", 2])
rowid = cursor.fetchone()[0]
conn.commit()

In [164]:
conn.rollback()

In [159]:
## /Inserting voth restaunrants and their cuisiness

In [165]:
restaurants


Out[165]:
[{'cuisines': ['deli', 'sandwiches'], 'name': 'Milano Market', 'price': 2},
 {'cuisines': ['ethiopian', 'african'], 'name': 'Massawa', 'price': 0},
 {'cuisines': ['chinese', 'japanese', 'sushi'],
  'name': 'China Place',
  'price': 0},
 {'cuisines': ['cheese-steaks', 'deli', 'sandwiches', 'salads'],
  'name': 'Subsconscious',
  'price': 0},
 {'cuisines': ['italian', 'pizza'], 'name': 'Famous Famiglia', 'price': 0},
 {'cuisines': ['bakery-pastries', 'american', 'desserts'],
  'name': 'Kitchenette',
  'price': 0},
 {'cuisines': ['italian', 'pizza'], 'name': 'V & T Pizza', 'price': 0},
 {'cuisines': ['chinese'], 'name': 'New Aroma', 'price': 1},
 {'cuisines': ['chinese'], 'name': 'Peking Garden', 'price': 1},
 {'cuisines': ['diner'], 'name': "Tom's Restaurant", 'price': 1},
 {'cuisines': ['italian'], 'name': 'Pisticci', 'price': 1},
 {'cuisines': ['diner', 'american'], 'name': 'Deluxe', 'price': 1},
 {'cuisines': ['american', 'bar-food'], 'name': 'Toast', 'price': 2},
 {'cuisines': ['italian', 'pizza'],
  'name': "Tom's Delicious Pizza",
  'price': 2},
 {'cuisines': ['chinese'], 'name': 'West Place', 'price': 1},
 {'cuisines': ['italian', 'pizza'], 'name': "Che' Bella Pizza", 'price': 0},
 {'cuisines': ['indian'], 'name': 'Ajanta', 'price': 0},
 {'cuisines': ['italian', 'coffee-tea', 'sandwiches'],
  'name': 'Panino Sportivo Roma',
  'price': 2},
 {'cuisines': ['italian'], 'name': 'Max Soha', 'price': 2},
 {'cuisines': ['deli', 'pizza', 'sandwiches', 'chicken'],
  'name': 'Strokos Pizza',
  'price': 3},
 {'cuisines': ['american'], 'name': "Camille's", 'price': 1},
 {'cuisines': ['american-new', 'tapas'],
  'name': 'Amsterdam Restaurant',
  'price': 1},
 {'cuisines': ['deli', 'sandwiches', 'bagels', 'salads'],
  'name': 'Nussbaum & Wu',
  'price': 0},
 {'cuisines': ['middle-eastern'], 'name': "Amir's Grill", 'price': 1},
 {'cuisines': ['japanese', 'sushi', 'deli', 'sandwiches'],
  'name': 'M2M - Morning To Midnight',
  'price': 1},
 {'cuisines': ['korean'], 'name': 'The Mill', 'price': 2},
 {'cuisines': ['french', 'bistro'], 'name': 'Le Monde', 'price': 1},
 {'cuisines': ['american-new', 'soul-food'], 'name': "Melba's", 'price': 1},
 {'cuisines': ['pizza', 'american'], 'name': "Chuck E Cheese's", 'price': 0},
 {'cuisines': ['desserts'], 'name': 'Haagen-Dazs', 'price': 1},
 {'cuisines': ['coffee-tea', 'sandwiches'], 'name': "Oren's", 'price': 0},
 {'cuisines': ['barbecue', 'soul-food'],
  'name': 'Dinosaur Bar-B-Que',
  'price': 3},
 {'cuisines': ['greek', 'vegetarian'],
  'name': 'Symposium Greek Restaurant',
  'price': 0},
 {'cuisines': ['pizza'], 'name': 'Koronet Pizza', 'price': 1},
 {'cuisines': ['southwestern', 'tapas', 'bar-food'],
  'name': 'The Heights Bar & Grill',
  'price': 1},
 {'cuisines': ['middle-eastern', 'kosher'], 'name': 'Cafe Nana', 'price': 0},
 {'cuisines': ['deli', 'sandwiches'], 'name': 'Hamilton Deli', 'price': 0},
 {'cuisines': ['american-new',
   'smoothies-juices',
   'vegetarian',
   'healthy',
   'localorganic'],
  'name': 'Community Food & Juice',
  'price': 0},
 {'cuisines': ['american', 'scandinavian'],
  'name': "Haakon's Hall",
  'price': 0},
 {'cuisines': ['mexican'], 'name': 'El Porton', 'price': 0},
 {'cuisines': ['coffee-tea'], 'name': "Brad's", 'price': 1},
 {'cuisines': ['burgers', 'bar-food'], 'name': "Mel's Burger Bar", 'price': 2},
 {'cuisines': ['italian', 'pizza', 'localorganic'],
  'name': 'Bettolona',
  'price': 1},
 {'cuisines': ['burgers', 'hot-dogs'], 'name': 'Five Guys', 'price': 1},
 {'cuisines': ['chinese', 'japanese', 'sushi', 'teahouses'],
  'name': 'Nikko',
  'price': 2},
 {'cuisines': ['middle-eastern'], 'name': 'Falafel on Broadway', 'price': 1},
 {'cuisines': ['japanese', 'sushi'], 'name': 'Sushi Sushi', 'price': 1},
 {'cuisines': ['bakery-pastries', 'desserts'],
  'name': 'Insomnia Cookies',
  'price': 1},
 {'cuisines': ['coffee-tea', 'sandwiches'], 'name': 'Cafe Amrita', 'price': 1},
 {'cuisines': ['desserts'], 'name': 'Pinkberry', 'price': 2},
 {'cuisines': ['coffee-tea', 'sandwiches', 'crepes'],
  'name': 'Artopolis Espresso Cafe',
  'price': 1},
 {'cuisines': ['coffee-tea', 'sandwiches'], 'name': 'Max Caffe', 'price': 2},
 {'cuisines': ['mexican'], 'name': 'Chipotle', 'price': 1},
 {'cuisines': ['bakery-pastries', 'desserts'],
  'name': 'Chokolat Patisserie',
  'price': 5},
 {'cuisines': ['bakery-pastries', 'coffee-tea', 'desserts'],
  'name': 'Chokolat Patisserie',
  'price': 1},
 {'cuisines': ['deli', 'sandwiches'], 'name': "Joe's G-H Deli", 'price': 2},
 {'cuisines': ['coffee-tea'], 'name': 'Joe the Art of Coffee', 'price': 1},
 {'cuisines': ['bakery-pastries', 'desserts'],
  'name': 'Levain Bakery',
  'price': 2},
 {'cuisines': ['middle-eastern', 'vegetarian'], 'name': 'Silvana', 'price': 1},
 {'cuisines': ['german', 'eclectic', 'bar-food'],
  'name': 'Bier International',
  'price': 1},
 {'cuisines': ['indian', 'vegetarian'], 'name': 'Vegenation', 'price': 1},
 {'cuisines': ['american-new', 'bistro'], 'name': 'Flat Top', 'price': 4},
 {'cuisines': ['coffee-tea'], 'name': 'Kuro Kuma', 'price': 1},
 {'cuisines': ['american-new'], 'name': 'Vinateria', 'price': 2},
 {'cuisines': ['chinese'], 'name': 'Henan Cart', 'price': 1},
 {'cuisines': ['japanese', 'sushi', 'thai'], 'name': 'Vine', 'price': 2},
 {'cuisines': ['mexican'], 'name': 'El Paso Truck', 'price': 1},
 {'cuisines': ['pizza', 'chicken'],
  'name': "Mama's Fried Chicken and Pizza",
  'price': 1},
 {'cuisines': ['indian'], 'name': 'Chapati House', 'price': 2},
 {'cuisines': ['american', 'localorganic'],
  'name': 'Dig Inn Seasonal Market',
  'price': 1},
 {'cuisines': ['chinese'], 'name': 'Uncle Luoyang', 'price': 1},
 {'cuisines': ['middle-eastern'], 'name': 'Pita Grill', 'price': 2},
 {'cuisines': ['japanese'], 'name': 'Kissaten Jin', 'price': 1},
 {'cuisines': ['coffee-tea', 'teahouses'],
  'name': 'Serengeti Teas & Spices',
  'price': 2},
 {'cuisines': ['seafood', 'wings', 'fish--chips'],
  'name': 'Lighthouse Fish Market & Restaurant',
  'price': 3},
 {'cuisines': ['seafood'], 'name': "Lolo's Seafood Shack", 'price': 2},
 {'cuisines': ['sandwiches', 'salads', 'teahouses'],
  'name': 'Harmony',
  'price': 1},
 {'cuisines': ['american', 'gastropub'],
  'name': 'Bernheim & Schwartz',
  'price': 2},
 {'cuisines': ['american-new'], 'name': 'BTH (By The Hudson)', 'price': 3},
 {'cuisines': [], 'name': 'Empanadas Monumental', 'price': 0},
 {'cuisines': [], 'name': "Friedman's", 'price': 0},
 {'cuisines': [], 'name': '176 Presbyterian Deli', 'price': 0},
 {'cuisines': [], 'name': "Nacho Mama's", 'price': 0},
 {'cuisines': [], 'name': 'Streetbird Rotisserie', 'price': 0},
 {'cuisines': [], 'name': 'Colum Chinese Restaurant', 'price': 0},
 {'cuisines': [], 'name': 'Flacoz Tacoz', 'price': 0},
 {'cuisines': [], 'name': 'sweetgreen', 'price': 0},
 {'cuisines': [], 'name': 'La Salle Dumpling Room', 'price': 0}]

In [166]:
rest_insert = "insert into restaurant (name, price) values (%s, %s) returning id"
cuisine  = "insert into cuisine (restaurant_id, kind) values (%s, %s)"
for item in restaurants:
    #execute sql statement with data from the restaurant!
    cursor.execute(rest_insert, [str(item['name']), item['price']])
    rowid = cursor.fetchone()[0]
    for cuisine in item['cuisines']:
        print(" - inserting cuisine", cuisine)
        cursor.execute(cuisine_insert, [rowid, str(cuisine)])
    # insert restaunrant_id, cuisine kind into cuisine table
conn.commit()


 - inserting cuisine deli
 - inserting cuisine sandwiches
 - inserting cuisine ethiopian
 - inserting cuisine african
 - inserting cuisine chinese
 - inserting cuisine japanese
 - inserting cuisine sushi
 - inserting cuisine cheese-steaks
 - inserting cuisine deli
 - inserting cuisine sandwiches
 - inserting cuisine salads
 - inserting cuisine italian
 - inserting cuisine pizza
 - inserting cuisine bakery-pastries
 - inserting cuisine american
 - inserting cuisine desserts
 - inserting cuisine italian
 - inserting cuisine pizza
 - inserting cuisine chinese
 - inserting cuisine chinese
 - inserting cuisine diner
 - inserting cuisine italian
 - inserting cuisine diner
 - inserting cuisine american
 - inserting cuisine american
 - inserting cuisine bar-food
 - inserting cuisine italian
 - inserting cuisine pizza
 - inserting cuisine chinese
 - inserting cuisine italian
 - inserting cuisine pizza
 - inserting cuisine indian
 - inserting cuisine italian
 - inserting cuisine coffee-tea
 - inserting cuisine sandwiches
 - inserting cuisine italian
 - inserting cuisine deli
 - inserting cuisine pizza
 - inserting cuisine sandwiches
 - inserting cuisine chicken
 - inserting cuisine american
 - inserting cuisine american-new
 - inserting cuisine tapas
 - inserting cuisine deli
 - inserting cuisine sandwiches
 - inserting cuisine bagels
 - inserting cuisine salads
 - inserting cuisine middle-eastern
 - inserting cuisine japanese
 - inserting cuisine sushi
 - inserting cuisine deli
 - inserting cuisine sandwiches
 - inserting cuisine korean
 - inserting cuisine french
 - inserting cuisine bistro
 - inserting cuisine american-new
 - inserting cuisine soul-food
 - inserting cuisine pizza
 - inserting cuisine american
 - inserting cuisine desserts
 - inserting cuisine coffee-tea
 - inserting cuisine sandwiches
 - inserting cuisine barbecue
 - inserting cuisine soul-food
 - inserting cuisine greek
 - inserting cuisine vegetarian
 - inserting cuisine pizza
 - inserting cuisine southwestern
 - inserting cuisine tapas
 - inserting cuisine bar-food
 - inserting cuisine middle-eastern
 - inserting cuisine kosher
 - inserting cuisine deli
 - inserting cuisine sandwiches
 - inserting cuisine american-new
 - inserting cuisine smoothies-juices
 - inserting cuisine vegetarian
 - inserting cuisine healthy
 - inserting cuisine localorganic
 - inserting cuisine american
 - inserting cuisine scandinavian
 - inserting cuisine mexican
 - inserting cuisine coffee-tea
 - inserting cuisine burgers
 - inserting cuisine bar-food
 - inserting cuisine italian
 - inserting cuisine pizza
 - inserting cuisine localorganic
 - inserting cuisine burgers
 - inserting cuisine hot-dogs
 - inserting cuisine chinese
 - inserting cuisine japanese
 - inserting cuisine sushi
 - inserting cuisine teahouses
 - inserting cuisine middle-eastern
 - inserting cuisine japanese
 - inserting cuisine sushi
 - inserting cuisine bakery-pastries
 - inserting cuisine desserts
 - inserting cuisine coffee-tea
 - inserting cuisine sandwiches
 - inserting cuisine desserts
 - inserting cuisine coffee-tea
 - inserting cuisine sandwiches
 - inserting cuisine crepes
 - inserting cuisine coffee-tea
 - inserting cuisine sandwiches
 - inserting cuisine mexican
 - inserting cuisine bakery-pastries
 - inserting cuisine desserts
 - inserting cuisine bakery-pastries
 - inserting cuisine coffee-tea
 - inserting cuisine desserts
 - inserting cuisine deli
 - inserting cuisine sandwiches
 - inserting cuisine coffee-tea
 - inserting cuisine bakery-pastries
 - inserting cuisine desserts
 - inserting cuisine middle-eastern
 - inserting cuisine vegetarian
 - inserting cuisine german
 - inserting cuisine eclectic
 - inserting cuisine bar-food
 - inserting cuisine indian
 - inserting cuisine vegetarian
 - inserting cuisine american-new
 - inserting cuisine bistro
 - inserting cuisine coffee-tea
 - inserting cuisine american-new
 - inserting cuisine chinese
 - inserting cuisine japanese
 - inserting cuisine sushi
 - inserting cuisine thai
 - inserting cuisine mexican
 - inserting cuisine pizza
 - inserting cuisine chicken
 - inserting cuisine indian
 - inserting cuisine american
 - inserting cuisine localorganic
 - inserting cuisine chinese
 - inserting cuisine middle-eastern
 - inserting cuisine japanese
 - inserting cuisine coffee-tea
 - inserting cuisine teahouses
 - inserting cuisine seafood
 - inserting cuisine wings
 - inserting cuisine fish--chips
 - inserting cuisine seafood
 - inserting cuisine sandwiches
 - inserting cuisine salads
 - inserting cuisine teahouses
 - inserting cuisine american
 - inserting cuisine gastropub
 - inserting cuisine american-new

In [ ]:
poem = """Whose woods these are I think I know
His house is in the village though"""